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