2
0

Repository.php 3.7 KB

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