示例#1
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 = Zend_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 = Zend_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 = Zend_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 = Zend_Tool_Rpc_Manifest_Registry::getInstance()->getMetadata(array('type' => 'Provider', 'providerName' => $provider->getName(), 'actionName' => $action->getName(), 'specialtyName' => $specialtyName, 'name' => 'cliActionableMethodLongParameters'));
     $cliActionableMethodShortParameterMetadata = Zend_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 Zend_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;
 }
示例#2
0
<?php

/**
 * DEV ONLY START - this will be removed when this hits incubator
 */
$zendFrameworkPath = getenv('ZF_PATH');
if ($zendFrameworkPath == '' || !file_exists($zendFrameworkPath)) {
    die('While in development: please set env var ZF_PATH to your copy of zend framework.' . PHP_EOL);
}
define('ZF_LIBRARY_PATH', $zendFrameworkPath);
define('CLI_LIBRARY_PATH', str_replace('\\', '/', dirname(__FILE__)) . '/../library/');
unset($zendFrameworkPath);
set_include_path(CLI_LIBRARY_PATH . PATH_SEPARATOR . ZF_LIBRARY_PATH);
/**
 * DEV ONLY STOP
 */
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
Zend_Tool_Rpc_Endpoint_Cli::main();