/zf/library/Zend/Tool/Framework/Action/Repository.php

http://github.com/eryx/php-framework-benchmark · PHP · 138 lines · 50 code · 16 blank · 72 comment · 7 complexity · 324e90ffd5d12b770585dfb2b12f5d4f MD5 · raw file

  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-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Repository.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_Tool_Framework_Registry_EnabledInterface
  24. */
  25. require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Tool
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Tool_Framework_Action_Repository
  33. implements Zend_Tool_Framework_Registry_EnabledInterface, IteratorAggregate, Countable
  34. {
  35. /**
  36. * @var Zend_Tool_Framework_Registry_Interface
  37. */
  38. protected $_registry = null;
  39. /**
  40. * @var array
  41. */
  42. protected $_actions = array();
  43. /**
  44. * setRegistry()
  45. *
  46. * @param Zend_Tool_Framework_Registry_Interface $registry
  47. */
  48. public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
  49. {
  50. $this->_registry = $registry;
  51. }
  52. /**
  53. * addAction()
  54. *
  55. * @param Zend_Tool_Framework_Action_Interface $action
  56. * @return Zend_Tool_Framework_Action_Repository
  57. */
  58. public function addAction(Zend_Tool_Framework_Action_Interface $action, $overrideExistingAction = false)
  59. {
  60. $actionName = $action->getName();
  61. if ($actionName == '' || $actionName == 'Base') {
  62. require_once 'Zend/Tool/Framework/Action/Exception.php';
  63. throw new Zend_Tool_Framework_Action_Exception('An action name for the provided action could not be determined.');
  64. }
  65. if (!$overrideExistingAction && array_key_exists(strtolower($actionName), $this->_actions)) {
  66. require_once 'Zend/Tool/Framework/Action/Exception.php';
  67. throw new Zend_Tool_Framework_Action_Exception('An action by the name ' . $actionName
  68. . ' is already registered and $overrideExistingAction is set to false.');
  69. }
  70. $this->_actions[strtolower($actionName)] = $action;
  71. return $this;
  72. }
  73. /**
  74. * process() - this is called when the client is done constructing (after init())
  75. *
  76. * @return unknown
  77. */
  78. public function process()
  79. {
  80. return null;
  81. }
  82. /**
  83. * getActions() - get all actions in the repository
  84. *
  85. * @return array
  86. */
  87. public function getActions()
  88. {
  89. return $this->_actions;
  90. }
  91. /**
  92. * getAction() - get an action by a specific name
  93. *
  94. * @param string $actionName
  95. * @return Zend_Tool_Framework_Action_Interface
  96. */
  97. public function getAction($actionName)
  98. {
  99. if (!array_key_exists(strtolower($actionName), $this->_actions)) {
  100. return null;
  101. }
  102. return $this->_actions[strtolower($actionName)];
  103. }
  104. /**
  105. * count() required by the Countable interface
  106. *
  107. * @return int
  108. */
  109. public function count()
  110. {
  111. return count($this->_actions);
  112. }
  113. /**
  114. * getIterator() - get all actions, this supports the IteratorAggregate interface
  115. *
  116. * @return array
  117. */
  118. public function getIterator()
  119. {
  120. return new ArrayIterator($this->_actions);
  121. }
  122. }