Example #1
0
 /**
  * initialized() - This will initialize the client for use
  *
  */
 public function initialize()
 {
     // if its already initialized, no need to initialize again
     if ($this->_isInitialized) {
         return;
     }
     // run any preInit
     $this->_preInit();
     $manifest = $this->_registry->getManifestRepository();
     $manifest->addManifest(new Manifest());
     // setup the debug log
     if (!$this->_debugLogger instanceof Log\Logger) {
         $this->_debugLogger = new Log\Logger(new Log\Writer\Null());
     }
     // let the loader load, then the repositories process whats been loaded
     $this->_registry->getLoader()->load();
     // process the action repository
     $this->_registry->getActionRepository()->process();
     // process the provider repository
     $this->_registry->getProviderRepository()->process();
     // process the manifest repository
     $this->_registry->getManifestRepository()->process();
     if ($this instanceof Interactive\InteractiveOutput) {
         $this->_registry->getResponse()->setContentCallback(array($this, 'handleInteractiveOutput'));
     }
 }
Example #2
0
 /**
  * getMetadata() is required by the Manifest Interface.
  *
  * These are the following metadatas that will be setup:
  *
  * normalizedActionName
  *   - metadata for actions
  *   - value will be a dashed name for the action named in 'actionName'
  * normalizedProviderName
  *   - metadata for providers
  *   - value will be a dashed-name for the provider named in 'providerName'
  * normalizedProviderSpecialtyNames
  *   - metadata for providers
  * normalizedActionableMethodLongParameters
  *   - metadata for providers
  * normalizedActionableMethodShortParameters
  *   - metadata for providers
  *
  * @return array Array of Metadatas
  */
 public function getMetadata()
 {
     $metadatas = array();
     // setup the camelCase to dashed filter to use since cli expects dashed named
     $lowerFilter = new \Zend\Filter\FilterChain();
     $lowerFilter->attach(new \Zend\Filter\StringToLower());
     // get the registry to get the action and provider repository
     $actionRepository = $this->_registry->getActionRepository();
     $providerRepository = $this->_registry->getProviderRepository();
     // loop through all actions and create a metadata for each
     foreach ($actionRepository->getActions() as $action) {
         // each action metadata will be called
         $metadatas[] = new Metadata\Tool(array('name' => 'normalizedActionName', 'value' => $lowerFilter->filter($action->getName()), 'reference' => $action, 'actionName' => $action->getName(), 'clientName' => 'all'));
     }
     foreach ($providerRepository->getProviderSignatures() as $providerSignature) {
         // create the metadata for the provider's cliProviderName
         $metadatas[] = new Metadata\Tool(array('name' => 'normalizedProviderName', 'value' => $lowerFilter->filter($providerSignature->getName()), 'reference' => $providerSignature, 'clientName' => 'all', 'providerName' => $providerSignature->getName()));
         // create the metadatas for the per provider specialites in providerSpecaltyNames
         foreach ($providerSignature->getSpecialties() as $specialty) {
             if ($specialty == '_Global') {
                 continue;
             }
             $metadatas[] = new Metadata\Tool(array('name' => 'normalizedSpecialtyName', 'value' => $lowerFilter->filter($specialty), 'reference' => $providerSignature, 'clientName' => 'all', 'providerName' => $providerSignature->getName(), 'specialtyName' => $specialty));
         }
         // $actionableMethod is keyed by the methodName (but not used)
         foreach ($providerSignature->getActionableMethods() as $actionableMethodData) {
             $methodLongParams = array();
             $methodShortParams = array();
             // $actionableMethodData get both the long and short names
             foreach ($actionableMethodData['parameterInfo'] as $parameterInfoData) {
                 // filter to dashed
                 $methodLongParams[$parameterInfoData['name']] = $lowerFilter->filter($parameterInfoData['name']);
                 // simply lower the character, (its only 1 char after all)
                 $methodShortParams[$parameterInfoData['name']] = strtolower($parameterInfoData['name'][0]);
             }
             // create metadata for the long name cliActionableMethodLongParameters
             $metadatas[] = new Metadata\Tool(array('name' => 'normalizedActionableMethodLongParams', 'value' => $methodLongParams, 'clientName' => 'console', 'providerName' => $providerSignature->getName(), 'specialtyName' => $actionableMethodData['specialty'], 'actionName' => $actionableMethodData['actionName'], 'reference' => &$actionableMethodData));
             // create metadata for the short name cliActionableMethodShortParameters
             $metadatas[] = new Metadata\Tool(array('name' => 'normalizedActionableMethodShortParams', 'value' => $methodShortParams, 'clientName' => 'console', 'providerName' => $providerSignature->getName(), 'specialtyName' => $actionableMethodData['specialty'], 'actionName' => $actionableMethodData['actionName'], 'reference' => &$actionableMethodData));
         }
     }
     return $metadatas;
 }
Example #3
0
    /**
     * _processActionableMethods() - process all methods that can be called on this provider.
     *
     */
    protected function _processActionableMethods()
    {

        $specialtyRegex = '#(.*)(' . implode('|', $this->_specialties) . ')$#i';


        $methods = $this->_providerReflection->getMethods();

        $actionableMethods = array();
        foreach ($methods as $method) {

            $methodName = $method->getName();

            /**
             * the following will determine what methods are actually actionable
             * public, non-static, non-underscore prefixed, classes that dont
             * contain the name "
             */
            if (!$method->getDeclaringClass()->isInstantiable()
                || !$method->isPublic()
                || $methodName[0] == '_'
                || $method->isStatic()
                || in_array($methodName, array('getContextClasses', 'getName')) // other protected public methods will nee to go here
                ) {
                continue;
            }

            /**
             * check to see if the method was a required method by a Zend_Tool_* interface
             */
            foreach ($method->getDeclaringClass()->getInterfaces() as $methodDeclaringClassInterface) {
                if (strpos($methodDeclaringClassInterface->getName(), 'Zend_Tool_') === 0
                    && $methodDeclaringClassInterface->hasMethod($methodName)) {
                    continue 2;
                }
            }

            $actionableName = ucfirst($methodName);

            if (substr($actionableName, -6) == 'Action') {
                $actionableName = substr($actionableName, 0, -6);
            }

            $actionableMethods[$methodName]['methodName'] = $methodName;

            $matches = null;
            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';
            }

            // get the action, and create non-existent actions when they dont exist (the true part below)
            $action = $this->_registry->getActionRepository()->getAction($actionableMethods[$methodName]['actionName']);
            if ($action == null) {
                $action = new \Zend\Tool\Framework\Action\Base($actionableMethods[$methodName]['actionName']);
                $this->_registry->getActionRepository()->addAction($action);
            }
            $actionableMethods[$methodName]['action'] = $action;

            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;
            }

            $matches = 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;
    }