web/lib/Zend/Tool/Framework/Client/Manifest.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Tool
       
    17  * @subpackage Framework
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Manifest.php 20785 2010-01-31 09:43:03Z mikaelkael $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Tool_Framework_Manifest_MetadataManifestable
       
    25  */
       
    26 require_once 'Zend/Tool/Framework/Manifest/MetadataManifestable.php';
       
    27 
       
    28 /**
       
    29  * @see Zend_Filter
       
    30  */
       
    31 require_once 'Zend/Filter.php';
       
    32 
       
    33 /**
       
    34  * @see Zend_Filter_Word_CamelCaseToDash
       
    35  */
       
    36 require_once 'Zend/Filter/Word/CamelCaseToDash.php';
       
    37 
       
    38 /**
       
    39  * @see Zend_Filter_StringToLower
       
    40  */
       
    41 require_once 'Zend/Filter/StringToLower.php';
       
    42 
       
    43 /**
       
    44  * @see Zend_Tool_Framework_Metadata_Tool
       
    45  */
       
    46 require_once 'Zend/Tool/Framework/Metadata/Tool.php';
       
    47 
       
    48 /**
       
    49  * @see Zend_Tool_Framework_Registry_EnabledInterface
       
    50  */
       
    51 require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php';
       
    52 
       
    53 /**
       
    54  * Zend_Tool_Framework_Client_ConsoleClient_Manifest
       
    55  * @category   Zend
       
    56  * @package    Zend_Tool
       
    57  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    58  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    59  */
       
    60 class Zend_Tool_Framework_Client_Manifest
       
    61     implements Zend_Tool_Framework_Registry_EnabledInterface,
       
    62                Zend_Tool_Framework_Manifest_MetadataManifestable
       
    63 {
       
    64 
       
    65     /**
       
    66      * @var Zend_Tool_Framework_Registry_Interface
       
    67      */
       
    68     protected $_registry = null;
       
    69 
       
    70     /**
       
    71      * setRegistry() - Required for the Zend_Tool_Framework_Registry_EnabledInterface interface
       
    72      *
       
    73      * @param Zend_Tool_Framework_Registry_Interface $registry
       
    74      * @return Zend_Tool_Framework_Client_Console_Manifest
       
    75      */
       
    76     public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
       
    77     {
       
    78         $this->_registry = $registry;
       
    79         return $this;
       
    80     }
       
    81 
       
    82     /**
       
    83      * getMetadata() is required by the Manifest Interface.
       
    84      *
       
    85      * These are the following metadatas that will be setup:
       
    86      *
       
    87      * normalizedActionName
       
    88      *   - metadata for actions
       
    89      *   - value will be a dashed name for the action named in 'actionName'
       
    90      * normalizedProviderName
       
    91      *   - metadata for providers
       
    92      *   - value will be a dashed-name for the provider named in 'providerName'
       
    93      * normalizedProviderSpecialtyNames
       
    94      *   - metadata for providers
       
    95      * normalizedActionableMethodLongParameters
       
    96      *   - metadata for providers
       
    97      * normalizedActionableMethodShortParameters
       
    98      *   - metadata for providers
       
    99      *
       
   100      * @return array Array of Metadatas
       
   101      */
       
   102     public function getMetadata()
       
   103     {
       
   104         $metadatas = array();
       
   105 
       
   106         // setup the camelCase to dashed filter to use since cli expects dashed named
       
   107         $lowerFilter = new Zend_Filter();
       
   108         $lowerFilter->addFilter(new Zend_Filter_StringToLower());
       
   109 
       
   110         // get the registry to get the action and provider repository
       
   111         $actionRepository   = $this->_registry->getActionRepository();
       
   112         $providerRepository = $this->_registry->getProviderRepository();
       
   113 
       
   114         // loop through all actions and create a metadata for each
       
   115         foreach ($actionRepository->getActions() as $action) {
       
   116             // each action metadata will be called
       
   117             $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
       
   118                 'name'            => 'normalizedActionName',
       
   119                 'value'           => $lowerFilter->filter($action->getName()),
       
   120                 'reference'       => $action,
       
   121                 'actionName'      => $action->getName(),
       
   122                 'clientName'      => 'all'
       
   123                 ));
       
   124         }
       
   125 
       
   126         foreach ($providerRepository->getProviderSignatures() as $providerSignature) {
       
   127 
       
   128             // create the metadata for the provider's cliProviderName
       
   129             $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
       
   130                 'name'            => 'normalizedProviderName',
       
   131                 'value'           => $lowerFilter->filter($providerSignature->getName()),
       
   132                 'reference'       => $providerSignature,
       
   133                 'clientName'      => 'all',
       
   134                 'providerName'    => $providerSignature->getName()
       
   135                 ));
       
   136 
       
   137             // create the metadatas for the per provider specialites in providerSpecaltyNames
       
   138             foreach ($providerSignature->getSpecialties() as $specialty) {
       
   139 
       
   140                 if ($specialty == '_Global') {
       
   141                     continue;
       
   142                 }
       
   143                 
       
   144                 $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
       
   145                     'name'            => 'normalizedSpecialtyName',
       
   146                     'value'           => $lowerFilter->filter($specialty),
       
   147                     'reference'       => $providerSignature,
       
   148                     'clientName'      => 'all',
       
   149                     'providerName'    => $providerSignature->getName(),
       
   150                     'specialtyName'   => $specialty
       
   151                     ));
       
   152 
       
   153             }
       
   154 
       
   155             // $actionableMethod is keyed by the methodName (but not used)
       
   156             foreach ($providerSignature->getActionableMethods() as $actionableMethodData) {
       
   157 
       
   158                 $methodLongParams  = array();
       
   159                 $methodShortParams = array();
       
   160 
       
   161                 // $actionableMethodData get both the long and short names
       
   162                 foreach ($actionableMethodData['parameterInfo'] as $parameterInfoData) {
       
   163 
       
   164                     // filter to dashed
       
   165                     $methodLongParams[$parameterInfoData['name']] = $lowerFilter->filter($parameterInfoData['name']);
       
   166 
       
   167                     // simply lower the character, (its only 1 char after all)
       
   168                     $methodShortParams[$parameterInfoData['name']] = strtolower($parameterInfoData['name'][0]);
       
   169 
       
   170                 }
       
   171 
       
   172                 // create metadata for the long name cliActionableMethodLongParameters
       
   173                 $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
       
   174                     'name'            => 'normalizedActionableMethodLongParams',
       
   175                     'value'           => $methodLongParams,
       
   176                     'clientName'      => 'console',
       
   177                     'providerName'    => $providerSignature->getName(),
       
   178                     'specialtyName'   => $actionableMethodData['specialty'],
       
   179                     'actionName'      => $actionableMethodData['actionName'],
       
   180                     'reference'       => &$actionableMethodData
       
   181                     ));
       
   182 
       
   183                 // create metadata for the short name cliActionableMethodShortParameters
       
   184                 $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
       
   185                     'name'            => 'normalizedActionableMethodShortParams',
       
   186                     'value'           => $methodShortParams,
       
   187                     'clientName'      => 'console',
       
   188                     'providerName'    => $providerSignature->getName(),
       
   189                     'specialtyName'   => $actionableMethodData['specialty'],
       
   190                     'actionName'      => $actionableMethodData['actionName'],
       
   191                     'reference'       => &$actionableMethodData
       
   192                     ));
       
   193 
       
   194             }
       
   195 
       
   196         }
       
   197 
       
   198         return $metadatas;
       
   199     }
       
   200 
       
   201     public function getIndex()
       
   202     {
       
   203         return 100000;
       
   204     }
       
   205 
       
   206 }