Esempio n. 1
0
 /**
  * Enter description here...
  *
  * @return ZendL_Tool_Rpc_Manifest_Registry
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Esempio n. 2
0
 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());
         }
     }
 }
Esempio n. 3
0
 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();
     }
 }
Esempio n. 4
0
 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());
         }
     }
 }
Esempio n. 5
0
 public function parse()
 {
     $endpointRequest = $this->_endpoint->getRequest();
     if ($this->_workingArguments[0] == $_SERVER["SCRIPT_NAME"]) {
         array_shift($this->_workingArguments);
     }
     if (!$this->_parseGlobalPart() || count($this->_workingArguments) == 0) {
         // @todo process global options?
         return;
     }
     $actionName = array_shift($this->_workingArguments);
     // is the action name valid?
     $cliActionNameMetadatas = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Action', 'name' => 'cliActionName'));
     foreach ($cliActionNameMetadatas as $cliActionNameMetadata) {
         if ($actionName == $cliActionNameMetadata->getValue()) {
             $action = $cliActionNameMetadata->getReference();
             break;
         }
     }
     $endpointRequest->setActionName($action->getName());
     /* @TODO Action Parameter Requirements */
     if (count($this->_workingArguments) == 0) {
         return;
     }
     if (!$this->_parseActionPart() || count($this->_workingArguments) == 0) {
         return;
     }
     $cliProviderName = array_shift($this->_workingArguments);
     $cliSpecialtyName = '_global';
     if (strstr($cliProviderName, '.')) {
         list($cliProviderName, $cliSpecialtyName) = explode('.', $cliProviderName);
     }
     $cliProviderNameMetadatas = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Provider', 'name' => 'cliProviderName'));
     foreach ($cliProviderNameMetadatas as $cliProviderNameMetadata) {
         if ($cliProviderName == $cliProviderNameMetadata->getValue()) {
             $provider = $cliProviderNameMetadata->getReference();
             break;
         }
     }
     $endpointRequest->setProviderName($provider->getName());
     $cliSpecialtyNameMetadatas = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Provider', 'providerName' => $provider->getName(), 'name' => 'cliSpecialtyNames'));
     foreach ($cliSpecialtyNameMetadatas as $cliSpecialtyNameMetadata) {
         if ($cliSpecialtyName == $cliSpecialtyNameMetadata->getValue()) {
             $specialtyName = $cliSpecialtyNameMetadata->getSpecialtyName();
             break;
         }
     }
     $endpointRequest->setSpecialtyName($specialtyName);
     $cliActionableMethodLongParameterMetadata = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadata(array('type' => 'Provider', 'providerName' => $provider->getName(), 'actionName' => $action->getName(), 'specialtyName' => $specialtyName, 'name' => 'cliActionableMethodLongParameters'));
     $cliActionableMethodShortParameterMetadata = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadata(array('type' => 'Provider', 'providerName' => $provider->getName(), 'actionName' => $action->getName(), 'specialtyName' => $specialtyName, 'name' => 'cliActionableMethodShortParameters'));
     $cliParameterNameShortValues = $cliActionableMethodShortParameterMetadata->getValue();
     $getoptOptions = array();
     foreach ($cliActionableMethodLongParameterMetadata->getValue() as $parameterNameLong => $cliParameterNameLong) {
         $optionConfig = $cliParameterNameLong . '|';
         $cliActionableMethodReferenceData = $cliActionableMethodLongParameterMetadata->getReference();
         if ($cliActionableMethodReferenceData['type'] == 'string' || $cliActionableMethodReferenceData['type'] == 'bool') {
             $optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . ($cliActionableMethodReferenceData['optional'] ? '-' : '=') . 's';
         } elseif (in_array($cliActionableMethodReferenceData['type'], array('int', 'integer', 'float'))) {
             $optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . ($cliActionableMethodReferenceData['optional'] ? '-' : '=') . 'i';
         } else {
             $optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . '-s';
         }
         $getoptOptions[$optionConfig] = $cliActionableMethodReferenceData['description'] != '' ? $cliActionableMethodReferenceData['description'] : 'No description available.';
     }
     $getoptParser = new ZendL_Console_Getopt($getoptOptions, $this->_workingArguments, array('parseAll' => false));
     $getoptParser->parse();
     foreach ($getoptParser->getOptions() as $option) {
         $value = $getoptParser->getOption($option);
         $endpointRequest->setProviderParameter($option, $value);
     }
     /*
     Zend_Debug::dump($getoptParser); 
     Zend_Debug::dump($endpointRequest);
     die();
     */
     $this->_workingArguments = $getoptParser->getRemainingArgs();
     return;
 }
Esempio n. 6
0
 public function parse()
 {
     $endpointRequest = $this->_endpoint->getRequest();
     // check to see if the first cli arg is the script name
     if ($this->_workingArguments[0] == $_SERVER["SCRIPT_NAME"]) {
         array_shift($this->_workingArguments);
     }
     // process global options
     if (!$this->_parseGlobalPart() || count($this->_workingArguments) == 0) {
         // @todo process global options?
         return;
     }
     // the next "word" should be the action name
     $cliWordActionName = array_shift($this->_workingArguments);
     // is the action name valid?
     $cliActionNameMetadatas = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Action', 'name' => 'cliActionName'));
     foreach ($cliActionNameMetadatas as $cliActionNameMetadata) {
         if ($cliWordActionName == $cliActionNameMetadata->getValue()) {
             $action = $cliActionNameMetadata->getReference();
             break;
         }
     }
     // if no action, handle error
     if (!isset($action)) {
         require_once 'ZendL/Tool/Rpc/Endpoint/Exception.php';
         throw new ZendL_Tool_Rpc_Endpoint_Exception('Action \'' . $cliWordActionName . '\' is not a valid action.');
     }
     // prepare action request name
     $endpointRequest->setActionName($action->getName());
     /* @TODO Action Parameter Requirements */
     // make sure there are more "words" on the command line
     if (count($this->_workingArguments) == 0) {
         return;
     }
     // get the cli "word" as the provider name from command line
     $cliWordProvider = array_shift($this->_workingArguments);
     $cliWordProviderSpecialty = '_global';
     // if there is notation for specialties? If so, break them up
     if (strstr($cliWordProvider, '.')) {
         list($cliWordProvider, $cliWordProviderSpecialty) = explode('.', $cliWordProvider);
     }
     // get the cli provider names from the manifest
     $cliProviderNameMetadatas = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Provider', 'name' => 'cliProviderName'));
     // find the provider signature for the given cli word provider name
     foreach ($cliProviderNameMetadatas as $cliProviderNameMetadata) {
         if ($cliWordProvider == $cliProviderNameMetadata->getValue()) {
             $providerSignature = $cliProviderNameMetadata->getReference();
             break;
         }
     }
     // if no provider signature found, handle error
     if (!isset($providerSignature)) {
         require_once 'ZendL/Tool/Rpc/Endpoint/Exception.php';
         throw new ZendL_Tool_Rpc_Endpoint_Exception('Provider \'' . $cliWordProvider . '\' is not a valid provider.');
     }
     // prepare provider request name
     $endpointRequest->setProviderName($providerSignature->getName());
     $cliSpecialtyNameMetadatas = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadatas(array('type' => 'Provider', 'providerName' => $providerSignature->getName(), 'name' => 'cliSpecialtyNames'));
     foreach ($cliSpecialtyNameMetadatas as $cliSpecialtyNameMetadata) {
         if ($cliWordProviderSpecialty == $cliSpecialtyNameMetadata->getValue()) {
             $specialtyName = $cliSpecialtyNameMetadata->getSpecialtyName();
             break;
         }
     }
     $endpointRequest->setSpecialtyName($specialtyName);
     $cliActionableMethodLongParameterMetadata = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadata(array('type' => 'Provider', 'providerName' => $providerSignature->getName(), 'actionName' => $action->getName(), 'specialtyName' => $specialtyName, 'name' => 'cliActionableMethodLongParameters'));
     $cliActionableMethodShortParameterMetadata = ZendL_Tool_Rpc_Manifest_Registry::getInstance()->getMetadata(array('type' => 'Provider', 'providerName' => $providerSignature->getName(), 'actionName' => $action->getName(), 'specialtyName' => $specialtyName, 'name' => 'cliActionableMethodShortParameters'));
     $cliParameterNameShortValues = $cliActionableMethodShortParameterMetadata->getValue();
     $getoptOptions = array();
     foreach ($cliActionableMethodLongParameterMetadata->getValue() as $parameterNameLong => $cliParameterNameLong) {
         $optionConfig = $cliParameterNameLong . '|';
         $cliActionableMethodReferenceData = $cliActionableMethodLongParameterMetadata->getReference();
         if ($cliActionableMethodReferenceData['type'] == 'string' || $cliActionableMethodReferenceData['type'] == 'bool') {
             $optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . ($cliActionableMethodReferenceData['optional'] ? '-' : '=') . 's';
         } elseif (in_array($cliActionableMethodReferenceData['type'], array('int', 'integer', 'float'))) {
             $optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . ($cliActionableMethodReferenceData['optional'] ? '-' : '=') . 'i';
         } else {
             $optionConfig .= $cliParameterNameShortValues[$parameterNameLong] . '-s';
         }
         $getoptOptions[$optionConfig] = $cliActionableMethodReferenceData['description'] != '' ? $cliActionableMethodReferenceData['description'] : 'No description available.';
     }
     $getoptParser = new ZendL_Console_Getopt($getoptOptions, $this->_workingArguments, array('parseAll' => false));
     $getoptParser->parse();
     foreach ($getoptParser->getOptions() as $option) {
         $value = $getoptParser->getOption($option);
         $endpointRequest->setProviderParameter($option, $value);
     }
     $this->_workingArguments = $getoptParser->getRemainingArgs();
     return;
 }