Exemplo n.º 1
0
 public function getMetadata()
 {
     $metadatas = array();
     $ccToDashedFilter = new Zend_Filter();
     $ccToDashedFilter->addFilter(new Zend_Filter_Word_CamelCaseToDash())->addFilter(new Zend_Filter_StringToLower());
     $providerRegistry = Zend_Tool_Rpc_Provider_Registry::getInstance();
     $cliActionNames = array();
     foreach ($providerRegistry->getActions() as $action) {
         $metadatas[] = new Zend_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 Zend_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 Zend_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 Zend_Tool_Rpc_Manifest_ProviderMetadata(array('providerName' => $providerSignature->getName(), 'specialtyName' => $actionableMethodData['specialty'], 'actionName' => $actionableMethodData['actionName'], 'name' => 'cliActionableMethodLongParameters', 'value' => $cliActionableMethodLongParameters, 'reference' => &$parameterInfoData));
             $metadatas[] = new Zend_Tool_Rpc_Manifest_ProviderMetadata(array('providerName' => $providerSignature->getName(), 'specialtyName' => $actionableMethodData['specialty'], 'actionName' => $actionableMethodData['actionName'], 'name' => 'cliActionableMethodShortParameters', 'value' => $cliActionableMethodShortParameters, 'reference' => &$parameterInfoData));
         }
     }
     return $metadatas;
 }
Exemplo n.º 2
0
 public function addManifest(Zend_Tool_Rpc_Manifest_Interface $manifest)
 {
     $index = count($this->_manifests);
     if (method_exists($manifest, 'getIndex')) {
         $index = $manifest->getIndex();
     }
     $providerRegistry = Zend_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;
 }
Exemplo n.º 3
0
 public function dispatch()
 {
     $providerSignature = Zend_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 Zend_Tool_Exception('Not a supported method.');
     }
 }
Exemplo n.º 4
0
 public function listAction()
 {
     $providerRegistry = Zend_Tool_Rpc_Provider_Registry::getInstance();
     foreach ($providerRegistry->getProviderSignatures() as $provider) {
         echo $provider->getName() . PHP_EOL;
     }
 }
Exemplo n.º 5
0
 /**
  * Enter description here...
  *
  * @return Zend_Tool_Rpc_Provider_Registry
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function create($name, $viewincluded = true)
 {
     $structureGraph = $this->_getExistingStructureGraph();
     $controllersDirectoryNode = $structureGraph->findNodeByContext('controllersDirectory');
     $controllerFileContext = Zend_Tool_Project_Structure_Context_Registry::getInstance()->getContext('controllerFile');
     $newNode = new Zend_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 = Zend_Tool_Rpc_Provider_Registry::getInstance()->getProvider('View');
         $viewProvider->create($name, 'index');
     }
 }
Exemplo n.º 7
0
 public final function __construct()
 {
     $this->_init();
     if ($this->_loader == null) {
         //require_once 'Zend/Tool/Rpc/Loader/IncludePathLoader.php';
         $this->_loader = new Zend_Tool_Rpc_Loader_IncludePathLoader();
     }
     $this->_loader->load();
     Zend_Tool_Rpc_Provider_Registry::getInstance()->process();
     Zend_Tool_Rpc_Manifest_Registry::getInstance()->process();
     if ($this->_request == null) {
         $this->_request = new Zend_Tool_Rpc_Endpoint_Request();
     }
     if ($this->_response == null) {
         $this->_response = new Zend_Tool_Rpc_Endpoint_Response();
     }
 }
Exemplo n.º 8
0
 public function load()
 {
     $files = $this->_getFiles();
     $manifestRegistry = Zend_Tool_Rpc_Manifest_Registry::getInstance();
     $providerRegistry = Zend_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('Zend_Tool_Rpc_Manifest_Interface') && !$reflectionClass->isAbstract()) {
             $manifestRegistry->addManifest($reflectionClass->newInstance());
         }
         if ($reflectionClass->implementsInterface('Zend_Tool_Rpc_Provider_Interface') && !$reflectionClass->isAbstract()) {
             $providerRegistry->addProvider($reflectionClass->newInstance());
         }
     }
 }
Exemplo n.º 9
0
 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);
         }
         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'] = Zend_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;
 }