File indexing completed on 2025-01-26 05:24:53

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_Controller
0017  * @subpackage Zend_Controller_Action_Helper
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_Controller_Action_Helper_Abstract
0025  */
0026 // require_once 'Zend/Controller/Action/Helper/Abstract.php';
0027 
0028 /**
0029  * Add to action stack
0030  *
0031  * @uses       Zend_Controller_Action_Helper_Abstract
0032  * @category   Zend
0033  * @package    Zend_Controller
0034  * @subpackage Zend_Controller_Action_Helper
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Controller_Action_Helper_ActionStack extends Zend_Controller_Action_Helper_Abstract
0039 {
0040     /**
0041      * @var Zend_Controller_Plugin_ActionStack
0042      */
0043     protected $_actionStack;
0044 
0045     /**
0046      * Constructor
0047      *
0048      * Register action stack plugin
0049      *
0050      * @return void
0051      */
0052     public function __construct()
0053     {
0054         $front = Zend_Controller_Front::getInstance();
0055         if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) {
0056             /**
0057              * @see Zend_Controller_Plugin_ActionStack
0058              */
0059             // require_once 'Zend/Controller/Plugin/ActionStack.php';
0060             $this->_actionStack = new Zend_Controller_Plugin_ActionStack();
0061             $front->registerPlugin($this->_actionStack, 97);
0062         } else {
0063             $this->_actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
0064         }
0065     }
0066 
0067     /**
0068      * Push onto the stack
0069      *
0070      * @param  Zend_Controller_Request_Abstract $next
0071      * @return Zend_Controller_Action_Helper_ActionStack Provides a fluent interface
0072      */
0073     public function pushStack(Zend_Controller_Request_Abstract $next)
0074     {
0075         $this->_actionStack->pushStack($next);
0076         return $this;
0077     }
0078 
0079     /**
0080      * Push a new action onto the stack
0081      *
0082      * @param  string $action
0083      * @param  string $controller
0084      * @param  string $module
0085      * @param  array  $params
0086      * @throws Zend_Controller_Action_Exception
0087      * @return Zend_Controller_Action_Helper_ActionStack
0088      */
0089     public function actionToStack($action, $controller = null, $module = null, array $params = array())
0090     {
0091         if ($action instanceof Zend_Controller_Request_Abstract) {
0092             return $this->pushStack($action);
0093         } elseif (!is_string($action)) {
0094             /**
0095              * @see Zend_Controller_Action_Exception
0096              */
0097             // require_once 'Zend/Controller/Action/Exception.php';
0098             throw new Zend_Controller_Action_Exception('ActionStack requires either a request object or minimally a string action');
0099         }
0100 
0101         $request = $this->getRequest();
0102 
0103         if ($request instanceof Zend_Controller_Request_Abstract === false){
0104             /**
0105              * @see Zend_Controller_Action_Exception
0106              */
0107             // require_once 'Zend/Controller/Action/Exception.php';
0108             throw new Zend_Controller_Action_Exception('Request object not set yet');
0109         }
0110 
0111         $controller = (null === $controller) ? $request->getControllerName() : $controller;
0112         $module = (null === $module) ? $request->getModuleName() : $module;
0113 
0114         /**
0115          * @see Zend_Controller_Request_Simple
0116          */
0117         // require_once 'Zend/Controller/Request/Simple.php';
0118         $newRequest = new Zend_Controller_Request_Simple($action, $controller, $module, $params);
0119 
0120         return $this->pushStack($newRequest);
0121     }
0122 
0123     /**
0124      * Perform helper when called as $this->_helper->actionStack() from an action controller
0125      *
0126      * Proxies to {@link simple()}
0127      *
0128      * @param  string $action
0129      * @param  string $controller
0130      * @param  string $module
0131      * @param  array $params
0132      * @return boolean
0133      */
0134     public function direct($action, $controller = null, $module = null, array $params = array())
0135     {
0136         return $this->actionToStack($action, $controller, $module, $params);
0137     }
0138 }