Manifest.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Tool_Framework_Manifest_MetadataManifestable
  24. */
  25. require_once 'Zend/Tool/Framework/Manifest/MetadataManifestable.php';
  26. /**
  27. * @see Zend_Filter
  28. */
  29. require_once 'Zend/Filter.php';
  30. /**
  31. * @see Zend_Filter_Word_CamelCaseToDash
  32. */
  33. require_once 'Zend/Filter/Word/CamelCaseToDash.php';
  34. /**
  35. * @see Zend_Filter_StringToLower
  36. */
  37. require_once 'Zend/Filter/StringToLower.php';
  38. /**
  39. * @see Zend_Tool_Framework_Metadata_Tool
  40. */
  41. require_once 'Zend/Tool/Framework/Metadata/Tool.php';
  42. /**
  43. * @see Zend_Tool_Framework_Registry_EnabledInterface
  44. */
  45. require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php';
  46. /**
  47. * Zend_Tool_Framework_Client_ConsoleClient_Manifest
  48. * @category Zend
  49. * @package Zend_Tool
  50. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  51. * @license http://framework.zend.com/license/new-bsd New BSD License
  52. */
  53. class Zend_Tool_Framework_Client_Manifest
  54. implements Zend_Tool_Framework_Registry_EnabledInterface,
  55. Zend_Tool_Framework_Manifest_MetadataManifestable
  56. {
  57. /**
  58. * @var Zend_Tool_Framework_Registry_Interface
  59. */
  60. protected $_registry = null;
  61. /**
  62. * setRegistry() - Required for the Zend_Tool_Framework_Registry_EnabledInterface interface
  63. *
  64. * @param Zend_Tool_Framework_Registry_Interface $registry
  65. * @return Zend_Tool_Framework_Client_Console_Manifest
  66. */
  67. public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
  68. {
  69. $this->_registry = $registry;
  70. return $this;
  71. }
  72. /**
  73. * getMetadata() is required by the Manifest Interface.
  74. *
  75. * These are the following metadatas that will be setup:
  76. *
  77. * normalizedActionName
  78. * - metadata for actions
  79. * - value will be a dashed name for the action named in 'actionName'
  80. * normalizedProviderName
  81. * - metadata for providers
  82. * - value will be a dashed-name for the provider named in 'providerName'
  83. * normalizedProviderSpecialtyNames
  84. * - metadata for providers
  85. * normalizedActionableMethodLongParameters
  86. * - metadata for providers
  87. * normalizedActionableMethodShortParameters
  88. * - metadata for providers
  89. *
  90. * @return array Array of Metadatas
  91. */
  92. public function getMetadata()
  93. {
  94. $metadatas = array();
  95. // setup the camelCase to dashed filter to use since cli expects dashed named
  96. $lowerFilter = new Zend_Filter();
  97. $lowerFilter->addFilter(new Zend_Filter_StringToLower());
  98. // get the registry to get the action and provider repository
  99. $actionRepository = $this->_registry->getActionRepository();
  100. $providerRepository = $this->_registry->getProviderRepository();
  101. // loop through all actions and create a metadata for each
  102. foreach ($actionRepository->getActions() as $action) {
  103. // each action metadata will be called
  104. $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
  105. 'name' => 'normalizedActionName',
  106. 'value' => $lowerFilter->filter($action->getName()),
  107. 'reference' => $action,
  108. 'actionName' => $action->getName(),
  109. 'clientName' => 'all'
  110. ));
  111. }
  112. foreach ($providerRepository->getProviderSignatures() as $providerSignature) {
  113. // create the metadata for the provider's cliProviderName
  114. $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
  115. 'name' => 'normalizedProviderName',
  116. 'value' => $lowerFilter->filter($providerSignature->getName()),
  117. 'reference' => $providerSignature,
  118. 'clientName' => 'all',
  119. 'providerName' => $providerSignature->getName()
  120. ));
  121. // create the metadatas for the per provider specialites in providerSpecaltyNames
  122. foreach ($providerSignature->getSpecialties() as $specialty) {
  123. if ($specialty == '_Global') {
  124. continue;
  125. }
  126. $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
  127. 'name' => 'normalizedSpecialtyName',
  128. 'value' => $lowerFilter->filter($specialty),
  129. 'reference' => $providerSignature,
  130. 'clientName' => 'all',
  131. 'providerName' => $providerSignature->getName(),
  132. 'specialtyName' => $specialty
  133. ));
  134. }
  135. // $actionableMethod is keyed by the methodName (but not used)
  136. foreach ($providerSignature->getActionableMethods() as $actionableMethodData) {
  137. $methodLongParams = array();
  138. $methodShortParams = array();
  139. // $actionableMethodData get both the long and short names
  140. foreach ($actionableMethodData['parameterInfo'] as $parameterInfoData) {
  141. // filter to dashed
  142. $methodLongParams[$parameterInfoData['name']] = $lowerFilter->filter($parameterInfoData['name']);
  143. // simply lower the character, (its only 1 char after all)
  144. $methodShortParams[$parameterInfoData['name']] = strtolower($parameterInfoData['name'][0]);
  145. }
  146. // create metadata for the long name cliActionableMethodLongParameters
  147. $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
  148. 'name' => 'normalizedActionableMethodLongParams',
  149. 'value' => $methodLongParams,
  150. 'clientName' => 'console',
  151. 'providerName' => $providerSignature->getName(),
  152. 'specialtyName' => $actionableMethodData['specialty'],
  153. 'actionName' => $actionableMethodData['actionName'],
  154. 'reference' => &$actionableMethodData
  155. ));
  156. // create metadata for the short name cliActionableMethodShortParameters
  157. $metadatas[] = new Zend_Tool_Framework_Metadata_Tool(array(
  158. 'name' => 'normalizedActionableMethodShortParams',
  159. 'value' => $methodShortParams,
  160. 'clientName' => 'console',
  161. 'providerName' => $providerSignature->getName(),
  162. 'specialtyName' => $actionableMethodData['specialty'],
  163. 'actionName' => $actionableMethodData['actionName'],
  164. 'reference' => &$actionableMethodData
  165. ));
  166. }
  167. }
  168. return $metadatas;
  169. }
  170. public function getIndex()
  171. {
  172. return 100000;
  173. }
  174. }