static function cacheMap($servicePath, $cacheFilePath) { if (!is_dir($servicePath)) { throw new Exception('Invalid directory [' . $servicePath . ']'); } $servicePath = realpath($servicePath); $serviceMap = array(); $classMap = KAutoloader::getClassMap(); $checkedClasses = array(); foreach ($classMap as $class => $classFilePath) { $classFilePath = realpath($classFilePath); if (strpos($classFilePath, $servicePath) === 0) { $reflectionClass = new ReflectionClass($class); if ($reflectionClass->isSubclassOf('KalturaBaseService')) { $docComment = $reflectionClass->getDocComment(); $parser = new KalturaDocCommentParser($docComment); $serviceId = strtolower($parser->serviceName); $serviceMap[$serviceId] = $class; } } $checkedClasses[] = $class; } $pluginServices = array(); $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaServices'); foreach ($pluginInstances as $pluginName => $pluginInstance) { $pluginServices = $pluginInstance->getServicesMap(); foreach ($pluginServices as $serviceName => $serviceClass) { $serviceName = strtolower($serviceName); $serviceId = "{$pluginName}_{$serviceName}"; $pluginServices[$serviceId] = $serviceClass; $serviceMap[$serviceId] = $serviceClass; } } $cachedFile = ''; $cachedFile .= '<?php' . PHP_EOL; $cachedFile .= 'self::$services = ' . var_export($serviceMap, true) . ';' . PHP_EOL; if (!is_dir(dirname($cacheFilePath))) { mkdir(dirname($cacheFilePath), 0777); } file_put_contents($cacheFilePath, $cachedFile); }
private function writeOrderByEnumForType(KalturaTypeReflector $type) { $map = KAutoloader::getClassMap(); if (!isset($map[$type->getType()])) { return; } $this->_txt = ""; $parentType = $type; while (1) { $parentType = $parentType->getParentTypeReflector(); if ($parentType === null || $parentType->isFilterable()) { break; } } $partnetClassName = $parentType ? $parentType->getType() . "OrderBy" : "KalturaStringEnum"; $enumName = $type->getType() . "OrderBy"; $enumPath = dirname($map[$type->getType()]) . "/filters/orderEnums/{$enumName}.php"; $subpackage = ($type->getPackage() == 'api' ? '' : 'api.') . 'filters.enum'; $this->appendLine("<?php"); $this->appendLine("/**"); $this->appendLine(" * @package " . $type->getPackage()); $this->appendLine(" * @subpackage {$subpackage}"); $this->appendLine(" */"); $this->appendLine("class {$enumName} extends {$partnetClassName}"); $this->appendLine("{"); foreach ($type->getCurrentProperties() as $prop) { $filters = $prop->getFilters(); foreach ($filters as $filter) { if ($filter == "order") { $this->appendLine("\tconst " . $this->getOrderByConst($prop->getName()) . "_ASC = \"+" . $prop->getName() . "\";"); $this->appendLine("\tconst " . $this->getOrderByConst($prop->getName()) . "_DESC = \"-" . $prop->getName() . "\";"); } } } $reflectionClass = new ReflectionClass($type->getType()); if (!$type->isAbstract() && $reflectionClass->getMethod("getExtraFilters")->getDeclaringClass()->getName() === $reflectionClass->getName()) { $extraFilters = $type->getInstance()->getExtraFilters(); if ($extraFilters) { foreach ($extraFilters as $filterFields) { if (!isset($filterFields["order"])) { continue; } $fieldName = $filterFields["order"]; $fieldConst = $this->getOrderByConst($fieldName); $this->appendLine("\tconst {$fieldConst}_ASC = \"+{$fieldName}\";"); $this->appendLine("\tconst {$fieldConst}_DESC = \"-{$fieldName}\";"); } } } $this->appendLine("}"); $this->writeToFile($enumPath, $this->_txt); }
protected function initClassMap() { if ($this->_classMap !== null) { return; } $this->_classMap = KAutoloader::getClassMap(); }
static function cacheMap($servicePath, $cacheFilePath) { if (!is_dir($servicePath)) { throw new Exception('Invalid directory [' . $servicePath . ']'); } $servicePath = realpath($servicePath); $serviceMap = array(); $classMap = KAutoloader::getClassMap(); $checkedClasses = array(); //Retrieve all service classes from the classMap. $serviceClasses = array(); foreach ($classMap as $class => $classFilePath) { $classFilePath = realpath($classFilePath); if (strpos($classFilePath, $servicePath) === 0) { $reflectionClass = new ReflectionClass($class); if ($reflectionClass->isSubclassOf('KalturaBaseService')) { $serviceDoccomment = new KalturaDocCommentParser($reflectionClass->getDocComment()); $serviceClasses[$serviceDoccomment->serviceName] = $class; } } } //Retrieve all plugin service classes. $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaServices'); foreach ($pluginInstances as $pluginName => $pluginInstance) { $pluginServices = $pluginInstance->getServicesMap(); foreach ($pluginServices as $serviceName => $serviceClass) { $serviceName = strtolower($serviceName); $serviceId = "{$pluginName}_{$serviceName}"; $serviceClasses[$serviceId] = $serviceClass; } } //Add core & plugin services to the services map $aliasActions = array(); foreach ($serviceClasses as $serviceId => $serviceClass) { $serviceReflectionClass = KalturaServiceReflector::constructFromClassName($serviceClass); $serviceMapEntry = new KalturaServiceActionItem(); $serviceMapEntry->serviceId = $serviceId; $serviceMapEntry->serviceClass = $serviceClass; $serviceMapEntry->serviceInfo = $serviceReflectionClass->getServiceInfo(); $actionMap = array(); $nativeActions = $serviceReflectionClass->getActions(); foreach ($nativeActions as $actionId => $actionName) { $actionMap[strtolower($actionId)] = array("serviceClass" => $serviceClass, "actionMethodName" => $actionName, "serviceId" => $serviceId, "actionName" => $actionId); } $serviceMapEntry->actionMap = $actionMap; $serviceMap[strtolower($serviceId)] = $serviceMapEntry; foreach ($serviceReflectionClass->getAliasActions() as $alias => $methodName) { $aliasActions[$alias] = "{$serviceId}.{$methodName}"; } } // add aliases foreach ($aliasActions as $aliasAction => $sourceAction) { list($aliasService, $aliasAction) = explode('.', $aliasAction); list($sourceService, $sourceAction) = explode('.', $sourceAction); $aliasService = strtolower($aliasService); $sourceService = strtolower($sourceService); $extServiceClass = $serviceClasses[$sourceService]; $serviceMap[$aliasService]->actionMap[strtolower($aliasAction)] = array("serviceClass" => $extServiceClass, "actionMethodName" => $sourceAction, "serviceId" => $sourceService, "actionName" => $aliasAction); } // filter out services that have no actions $serviceMap = array_filter($serviceMap, array('KalturaServicesMap', 'filterEmptyServices')); if (!is_dir(dirname($cacheFilePath))) { mkdir(dirname($cacheFilePath)); chmod(dirname($cacheFilePath), 0755); } kFile::safeFilePutContents($cacheFilePath, serialize($serviceMap), 0644); }
private function getClassFilePath($class) { $map = KAutoloader::getClassMap(); if (!isset($map[$class])) { throw new Exception("File path was not found for [{$class}]"); } return $map[$class]; }