public function addManifest(ZendL_Tool_Rpc_Manifest_Interface $manifest) { $index = count($this->_manifests); if (method_exists($manifest, 'getIndex')) { $index = $manifest->getIndex(); } $providerRegistry = ZendL_Tool_Rpc_Provider_Registry::getInstance(); // load providers if interface supports that method if (method_exists($manifest, 'getProviders')) { $providers = $manifest->getProviders(); if (!is_array($providers)) { $providers = array($providers); } foreach ($providers as $provider) { $providerRegistry->addProvider($provider); } } // load actions if interface supports that method if (method_exists($manifest, 'getActions')) { $actions = $manifest->getActions(); if (!is_array($actions)) { $actions = array($actions); } foreach ($actions as $action) { $providerRegistry->addAction($action); } } $this->_manifests[$index] = $manifest; }
public function listAction() { $providerRegistry = ZendL_Tool_Rpc_Provider_Registry::getInstance(); foreach ($providerRegistry->getProviderSignatures() as $provider) { echo $provider->getName() . PHP_EOL; } }
public function getMetadata() { $metadatas = array(); $ccToDashedFilter = new Zend_Filter(); $ccToDashedFilter->addFilter(new Zend_Filter_Word_CamelCaseToDash())->addFilter(new Zend_Filter_StringToLower()); $providerRegistry = ZendL_Tool_Rpc_Provider_Registry::getInstance(); $cliActionNames = array(); foreach ($providerRegistry->getActions() as $action) { $metadatas[] = new ZendL_Tool_Rpc_Manifest_ActionMetadata(array('actionName' => $action->getName(), 'name' => 'cliActionName', 'value' => $ccToDashedFilter->filter($action->getName()), 'reference' => $action)); } foreach ($providerRegistry->getProviderSignatures() as $providerSignature) { $group = $providerSignature->getName(); $cliProviderName = $ccToDashedFilter->filter($group); $metadatas[] = new ZendL_Tool_Rpc_Manifest_ProviderMetadata(array('providerName' => $providerSignature->getName(), 'name' => 'cliProviderName', 'value' => $cliProviderName, 'reference' => $providerSignature)); $cliSpecialtyNames = array(); $providerSignatureSpecialties = $providerSignature->getSpecialties(); foreach ($providerSignatureSpecialties as $specialty) { //$cliSpecialtyNames[$specialty] = $ccToDashedFilter->filter($specialty); $metadatas[] = new ZendL_Tool_Rpc_Manifest_ProviderMetadata(array('providerName' => $providerSignature->getName(), 'specialtyName' => $specialty, 'name' => 'cliSpecialtyNames', 'value' => $ccToDashedFilter->filter($specialty))); } $cliActionableMethodLongParameters = $cliActionableMethodShortParameters = array(); $actionableMethods = $providerSignature->getActionableMethods(); foreach ($actionableMethods as $methodName => $actionableMethodData) { foreach ($actionableMethodData['parameterInfo'] as $parameterName => $parameterInfoData) { $cliActionableMethodLongParameters[$parameterInfoData['name']] = $ccToDashedFilter->filter($parameterInfoData['name']); $cliActionableMethodShortParameters[$parameterInfoData['name']] = strtolower($parameterInfoData['name'][0]); } $metadatas[] = new ZendL_Tool_Rpc_Manifest_ProviderMetadata(array('providerName' => $providerSignature->getName(), 'specialtyName' => $actionableMethodData['specialty'], 'actionName' => $actionableMethodData['actionName'], 'name' => 'cliActionableMethodLongParameters', 'value' => $cliActionableMethodLongParameters, 'reference' => &$parameterInfoData)); $metadatas[] = new ZendL_Tool_Rpc_Manifest_ProviderMetadata(array('providerName' => $providerSignature->getName(), 'specialtyName' => $actionableMethodData['specialty'], 'actionName' => $actionableMethodData['actionName'], 'name' => 'cliActionableMethodShortParameters', 'value' => $cliActionableMethodShortParameters, 'reference' => &$parameterInfoData)); } } return $metadatas; }
/** * Enter description here... * * @return ZendL_Tool_Rpc_Provider_Registry */ public static function getInstance() { if (self::$_instance === null) { self::$_instance = new self(); } return self::$_instance; }
public function dispatch() { $providerSignature = ZendL_Tool_Rpc_Provider_Registry::getInstance()->getProviderSignature($this->_request->getProviderName()); $provider = $providerSignature->getProvider(); $actionName = $this->_request->getActionName(); if (!($actionableMethod = $providerSignature->getActionableMethod($actionName))) { require_once 'ZendL/Tool/Rpc/Endpoint/Exception.php'; throw new ZendL_Tool_Rpc_Endpoint_Exception('Dispatcher error - actionable method not found'); } $methodName = $actionableMethod['methodName']; $methodParameters = $actionableMethod['parameterInfo']; $requestParameters = $this->_request->getProviderParameters(); // @todo This seems hackish, determine if there is a better way $callParameters = array(); foreach ($methodParameters as $methodParameterName => $methodParameterValue) { $callParameters[] = array_key_exists($methodParameterName, $requestParameters) ? $requestParameters[$methodParameterName] : $methodParameterValue['default']; } if (($specialtyName = $this->_request->getSpecialtyName()) != '_Global') { $methodName .= $specialtyName; } if (method_exists($provider, $methodName)) { call_user_func_array(array($provider, $methodName), $callParameters); } elseif (method_exists($provider, $methodName . 'Action')) { $method .= 'Action'; call_user_func_array(array($provider, $methodName), $callParameters); } else { require_once 'ZendL/Tool/Rpc/Endpoint/Exception.php'; throw new ZendL_Tool_Rpc_Endpoint_Exception('Not a supported method.'); } }
public function dispatch() { $providerSignature = ZendL_Tool_Rpc_Provider_Registry::getInstance()->getProviderSignature($this->_request->getProviderName()); $provider = $providerSignature->getProvider(); $method = $this->_request->getActionName(); $signatureParameters = $providerSignature->getActionableMethods(); $signatureParametersLower = array_change_key_case($signatureParameters, CASE_LOWER); $methodParameters = $signatureParametersLower[strtolower($method)]['parameterInfo']; $requestParameters = $this->_request->getProviderParameters(); // @todo This seems hackish, determine if there is a better way $callParameters = array(); foreach ($methodParameters as $methodParameterName => $methodParameterValue) { $callParameters[] = array_key_exists($methodParameterName, $requestParameters) ? $requestParameters[$methodParameterName] : $methodParameterValue['default']; } if (($specialtyName = $this->_request->getSpecialtyName()) != '_Global') { $method .= $specialtyName; } if (method_exists($provider, $method)) { call_user_func_array(array($provider, $method), $callParameters); } elseif (method_exists($provider, $method . 'Action')) { $method .= 'Action'; call_user_func_array(array($provider, $method), $callParameters); } else { throw new ZendL_Tool_Exception('Not a supported method.'); } }
public function load() { $files = $this->_getFiles(); $manifestRegistry = ZendL_Tool_Rpc_Manifest_Registry::getInstance(); $providerRegistry = ZendL_Tool_Rpc_Provider_Registry::getInstance(); $classesLoadedBefore = get_declared_classes(); $oldLevel = error_reporting(E_ALL | ~E_STRICT); // remove strict so that other packages wont throw warnings foreach ($files as $file) { require_once $file; } error_reporting($oldLevel); // restore old error level $classesLoadedAfter = get_declared_classes(); $loadedClasses = array_diff($classesLoadedAfter, $classesLoadedBefore); foreach ($loadedClasses as $loadedClass) { $reflectionClass = new ReflectionClass($loadedClass); if ($reflectionClass->implementsInterface('ZendL_Tool_Rpc_Manifest_Interface') && !$reflectionClass->isAbstract()) { $manifestRegistry->addManifest($reflectionClass->newInstance()); } if ($reflectionClass->implementsInterface('ZendL_Tool_Rpc_Provider_Interface') && !$reflectionClass->isAbstract()) { $providerRegistry->addProvider($reflectionClass->newInstance()); } } }
public function create($name, $controllername = 'index', $viewincluded = true) { $actionName = $name; $structureGraph = $this->_getExistingStructureGraph(); $controllerFileNode = $structureGraph->findNodeByContext(array('controllerFile' => array('controllerName' => $controllername))); $controllerContext = $controllerFileNode->getContext(); echo 'Adding action \'' . $actionName . '\' to controller \'' . $controllername . PHP_EOL; $controllerContext->addAction($actionName); if ($viewincluded) { $viewProvider = ZendL_Tool_Rpc_Provider_Registry::getInstance()->getProvider('View'); $viewProvider->create($controllername, $actionName); } }
public function create($name, $viewincluded = true) { $structureGraph = $this->_getExistingStructureGraph(); $controllersDirectoryNode = $structureGraph->findNodeByContext('controllersDirectory'); $controllerFileContext = ZendL_Tool_Project_Structure_Context_Registry::getInstance()->getContext('controllerFile'); $newNode = new ZendL_Tool_Project_Structure_Node($controllerFileContext); $newNode->setBaseDirectory($controllersDirectoryNode->getContext()->getPath()); $newNode->setControllerName($name); echo 'Creating new controller named \'' . $name . '\'' . PHP_EOL; $newNode->create(); $controllersDirectoryNode->append($newNode); $this->_storeLoadedStructureGraph(); if ($viewincluded) { $viewProvider = ZendL_Tool_Rpc_Provider_Registry::getInstance()->getProvider('View'); $viewProvider->create($name, 'index'); } }
public final function __construct() { $this->_init(); if ($this->_loader == null) { //require_once 'ZendL/Tool/Rpc/Loader/IncludePathLoader.php'; $this->_loader = new ZendL_Tool_Rpc_Loader_IncludePathLoader(); } $this->_loader->load(); ZendL_Tool_Rpc_Provider_Registry::getInstance()->process(); ZendL_Tool_Rpc_Manifest_Registry::getInstance()->process(); if ($this->_request == null) { $this->_request = new ZendL_Tool_Rpc_Endpoint_Request(); } if ($this->_response == null) { $this->_response = new ZendL_Tool_Rpc_Endpoint_Response(); } }
public function load() { $files = $this->_getFiles(); $manifestRegistry = ZendL_Tool_Rpc_Manifest_Registry::getInstance(); $providerRegistry = ZendL_Tool_Rpc_Provider_Registry::getInstance(); $classesLoadedBefore = get_declared_classes(); foreach ($files as $file) { Zend_Loader::loadFile($file); } $classesLoadedAfter = get_declared_classes(); $loadedClasses = array_diff($classesLoadedAfter, $classesLoadedBefore); foreach ($loadedClasses as $loadedClass) { $reflectionClass = new ReflectionClass($loadedClass); if ($reflectionClass->implementsInterface('ZendL_Tool_Rpc_Manifest_Interface') && !$reflectionClass->isAbstract()) { $manifestRegistry->addManifest($reflectionClass->newInstance()); } if ($reflectionClass->implementsInterface('ZendL_Tool_Rpc_Provider_Interface') && !$reflectionClass->isAbstract()) { $providerRegistry->addProvider($reflectionClass->newInstance()); } } }
protected function _processActionableMethods() { $specialtyRegex = '#(.*)(' . implode('|', $this->_specialties) . ')$#i'; $methods = $this->_providerReflection->getMethods(); $actionableMethods = array(); foreach ($methods as $method) { $methodName = $method->getName(); if (!$method->getDeclaringClass()->isInstantiable() || !$method->isPublic() || $methodName[0] == '_') { continue; } $actionableName = ucfirst($methodName); if (substr($actionableName, -6) == 'Action') { $actionableName = substr($actionableName, 0, -6); } $actionableMethods[$methodName]['methodName'] = $methodName; if (preg_match($specialtyRegex, $actionableName, $matches)) { $actionableMethods[$methodName]['actionName'] = $matches[1]; $actionableMethods[$methodName]['specialty'] = $matches[2]; } else { $actionableMethods[$methodName]['actionName'] = $actionableName; $actionableMethods[$methodName]['specialty'] = '_Global'; } $actionableMethods[$methodName]['action'] = ZendL_Tool_Rpc_Provider_Registry::getInstance()->getAction($actionableMethods[$methodName]['actionName']); if (!in_array($actionableMethods[$methodName]['action'], $this->_actions)) { $this->_actions[] = $actionableMethods[$methodName]['action']; } $parameterInfo = array(); $position = 1; foreach ($method->getParameters() as $parameter) { $currentParam = $parameter->getName(); $parameterInfo[$currentParam]['position'] = $position++; $parameterInfo[$currentParam]['optional'] = $parameter->isOptional(); $parameterInfo[$currentParam]['default'] = $parameter->isOptional() ? $parameter->getDefaultValue() : null; $parameterInfo[$currentParam]['name'] = $currentParam; $parameterInfo[$currentParam]['type'] = 'string'; $parameterInfo[$currentParam]['description'] = null; } if (($docComment = $method->getDocComment()) != '' && preg_match_all('/@param\\s+(\\w+)+\\s+(\\$\\S+)\\s+(.*?)(?=(?:\\*\\s*@)|(?:\\*\\/))/s', $docComment, $matches)) { for ($i = 0; $i <= count($matches[0]) - 1; $i++) { $currentParam = ltrim($matches[2][$i], '$'); if ($currentParam != '' && isset($parameterInfo[$currentParam])) { $parameterInfo[$currentParam]['type'] = $matches[1][$i]; $descriptionSource = $matches[3][$i]; if ($descriptionSource != '') { $parameterInfo[$currentParam]['description'] = trim($descriptionSource); } } } } $actionableMethods[$methodName]['parameterInfo'] = $parameterInfo; } $this->_actionableMethods = $actionableMethods; }