File indexing completed on 2025-01-19 05:21:35

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Tool
0017  * @subpackage Framework
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Tool_Framework_Registry_EnabledInterface
0025  */
0026 // require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php';
0027 
0028 /**
0029  * @category   Zend
0030  * @package    Zend_Tool
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Tool_Framework_Action_Repository
0035     implements Zend_Tool_Framework_Registry_EnabledInterface, IteratorAggregate, Countable
0036 {
0037 
0038     /**
0039      * @var Zend_Tool_Framework_Registry_Interface
0040      */
0041     protected $_registry = null;
0042 
0043     /**
0044      * @var array
0045      */
0046     protected $_actions = array();
0047 
0048     /**
0049      * setRegistry()
0050      *
0051      * @param Zend_Tool_Framework_Registry_Interface $registry
0052      */
0053     public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
0054     {
0055         $this->_registry = $registry;
0056     }
0057 
0058     /**
0059      * addAction()
0060      *
0061      * @param Zend_Tool_Framework_Action_Interface $action
0062      * @return Zend_Tool_Framework_Action_Repository
0063      */
0064     public function addAction(Zend_Tool_Framework_Action_Interface $action, $overrideExistingAction = false)
0065     {
0066         $actionName = $action->getName();
0067 
0068         if ($actionName == '' || $actionName == 'Base') {
0069             // require_once 'Zend/Tool/Framework/Action/Exception.php';
0070             throw new Zend_Tool_Framework_Action_Exception('An action name for the provided action could not be determined.');
0071         }
0072 
0073         if (!$overrideExistingAction && array_key_exists(strtolower($actionName), $this->_actions)) {
0074             // require_once 'Zend/Tool/Framework/Action/Exception.php';
0075             throw new Zend_Tool_Framework_Action_Exception('An action by the name ' . $actionName
0076                 . ' is already registered and $overrideExistingAction is set to false.');
0077         }
0078 
0079         $this->_actions[strtolower($actionName)] = $action;
0080         return $this;
0081     }
0082 
0083     /**
0084      * process() - this is called when the client is done constructing (after init())
0085      *
0086      * @return unknown
0087      */
0088     public function process()
0089     {
0090         return null;
0091     }
0092 
0093     /**
0094      * getActions() - get all actions in the repository
0095      *
0096      * @return array
0097      */
0098     public function getActions()
0099     {
0100         return $this->_actions;
0101     }
0102 
0103     /**
0104      * getAction() - get an action by a specific name
0105      *
0106      * @param string $actionName
0107      * @return Zend_Tool_Framework_Action_Interface
0108      */
0109     public function getAction($actionName)
0110     {
0111         if (!array_key_exists(strtolower($actionName), $this->_actions)) {
0112             return null;
0113         }
0114 
0115         return $this->_actions[strtolower($actionName)];
0116     }
0117 
0118     /**
0119      * count() required by the Countable interface
0120      *
0121      * @return int
0122      */
0123     public function count()
0124     {
0125         return count($this->_actions);
0126     }
0127 
0128     /**
0129      * getIterator() - get all actions, this supports the IteratorAggregate interface
0130      *
0131      * @return array
0132      */
0133     public function getIterator()
0134     {
0135         return new ArrayIterator($this->_actions);
0136     }
0137 
0138 }