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.
16 * @package Zend_Controller
17 * @subpackage Zend_Controller_Action_Helper
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: ActionStack.php 16202 2009-06-21 18:53:49Z thomas $
24 * @see Zend_Controller_Action_Helper_Abstract
26 require_once 'Zend/Controller/Action/Helper/Abstract.php';
31 * @uses Zend_Controller_Action_Helper_Abstract
33 * @package Zend_Controller
34 * @subpackage Zend_Controller_Action_Helper
35 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_Controller_Action_Helper_ActionStack
extends Zend_Controller_Action_Helper_Abstract
41 * @var Zend_Controller_Plugin_ActionStack
43 protected $_actionStack;
48 * Register action stack plugin
52 public function __construct()
54 $front = Zend_Controller_Front
::getInstance();
55 if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) {
57 * @see Zend_Controller_Plugin_ActionStack
59 require_once 'Zend/Controller/Plugin/ActionStack.php';
60 $this->_actionStack
= new Zend_Controller_Plugin_ActionStack();
61 $front->registerPlugin($this->_actionStack
, 97);
63 $this->_actionStack
= $front->getPlugin('Zend_Controller_Plugin_ActionStack');
70 * @param Zend_Controller_Request_Abstract $next
71 * @return Zend_Controller_Action_Helper_ActionStack Provides a fluent interface
73 public function pushStack(Zend_Controller_Request_Abstract
$next)
75 $this->_actionStack
->pushStack($next);
80 * Push a new action onto the stack
82 * @param string $action
83 * @param string $controller
84 * @param string $module
85 * @param array $params
86 * @throws Zend_Controller_Action_Exception
87 * @return Zend_Controller_Action_Helper_ActionStack
89 public function actionToStack($action, $controller = null, $module = null, array $params = array())
91 if ($action instanceof Zend_Controller_Request_Abstract
) {
92 return $this->pushStack($action);
93 } elseif (!is_string($action)) {
95 * @see Zend_Controller_Action_Exception
97 require_once 'Zend/Controller/Action/Exception.php';
98 throw new Zend_Controller_Action_Exception('ActionStack requires either a request object or minimally a string action');
101 $request = $this->getRequest();
103 if ($request instanceof Zend_Controller_Request_Abstract
=== false){
105 * @see Zend_Controller_Action_Exception
107 require_once 'Zend/Controller/Action/Exception.php';
108 throw new Zend_Controller_Action_Exception('Request object not set yet');
111 $controller = (null === $controller) ?
$request->getControllerName() : $controller;
112 $module = (null === $module) ?
$request->getModuleName() : $module;
115 * @see Zend_Controller_Request_Simple
117 require_once 'Zend/Controller/Request/Simple.php';
118 $newRequest = new Zend_Controller_Request_Simple($action, $controller, $module, $params);
120 return $this->pushStack($newRequest);
124 * Perform helper when called as $this->_helper->actionStack() from an action controller
126 * Proxies to {@link simple()}
128 * @param string $action
129 * @param string $controller
130 * @param string $module
131 * @param array $params
134 public function direct($action, $controller = null, $module = null, array $params = array())
136 return $this->actionToStack($action, $controller, $module, $params);