|
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_Controller |
|
17 * @subpackage Zend_Controller_Action_Helper |
|
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: ActionStack.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Controller_Action_Helper_Abstract |
|
25 */ |
|
26 require_once 'Zend/Controller/Action/Helper/Abstract.php'; |
|
27 |
|
28 /** |
|
29 * Add to action stack |
|
30 * |
|
31 * @uses Zend_Controller_Action_Helper_Abstract |
|
32 * @category Zend |
|
33 * @package Zend_Controller |
|
34 * @subpackage Zend_Controller_Action_Helper |
|
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
37 */ |
|
38 class Zend_Controller_Action_Helper_ActionStack extends Zend_Controller_Action_Helper_Abstract |
|
39 { |
|
40 /** |
|
41 * @var Zend_Controller_Plugin_ActionStack |
|
42 */ |
|
43 protected $_actionStack; |
|
44 |
|
45 /** |
|
46 * Constructor |
|
47 * |
|
48 * Register action stack plugin |
|
49 * |
|
50 * @return void |
|
51 */ |
|
52 public function __construct() |
|
53 { |
|
54 $front = Zend_Controller_Front::getInstance(); |
|
55 if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) { |
|
56 /** |
|
57 * @see Zend_Controller_Plugin_ActionStack |
|
58 */ |
|
59 require_once 'Zend/Controller/Plugin/ActionStack.php'; |
|
60 $this->_actionStack = new Zend_Controller_Plugin_ActionStack(); |
|
61 $front->registerPlugin($this->_actionStack, 97); |
|
62 } else { |
|
63 $this->_actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack'); |
|
64 } |
|
65 } |
|
66 |
|
67 /** |
|
68 * Push onto the stack |
|
69 * |
|
70 * @param Zend_Controller_Request_Abstract $next |
|
71 * @return Zend_Controller_Action_Helper_ActionStack Provides a fluent interface |
|
72 */ |
|
73 public function pushStack(Zend_Controller_Request_Abstract $next) |
|
74 { |
|
75 $this->_actionStack->pushStack($next); |
|
76 return $this; |
|
77 } |
|
78 |
|
79 /** |
|
80 * Push a new action onto the stack |
|
81 * |
|
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 |
|
88 */ |
|
89 public function actionToStack($action, $controller = null, $module = null, array $params = array()) |
|
90 { |
|
91 if ($action instanceof Zend_Controller_Request_Abstract) { |
|
92 return $this->pushStack($action); |
|
93 } elseif (!is_string($action)) { |
|
94 /** |
|
95 * @see Zend_Controller_Action_Exception |
|
96 */ |
|
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'); |
|
99 } |
|
100 |
|
101 $request = $this->getRequest(); |
|
102 |
|
103 if ($request instanceof Zend_Controller_Request_Abstract === false){ |
|
104 /** |
|
105 * @see Zend_Controller_Action_Exception |
|
106 */ |
|
107 require_once 'Zend/Controller/Action/Exception.php'; |
|
108 throw new Zend_Controller_Action_Exception('Request object not set yet'); |
|
109 } |
|
110 |
|
111 $controller = (null === $controller) ? $request->getControllerName() : $controller; |
|
112 $module = (null === $module) ? $request->getModuleName() : $module; |
|
113 |
|
114 /** |
|
115 * @see Zend_Controller_Request_Simple |
|
116 */ |
|
117 require_once 'Zend/Controller/Request/Simple.php'; |
|
118 $newRequest = new Zend_Controller_Request_Simple($action, $controller, $module, $params); |
|
119 |
|
120 return $this->pushStack($newRequest); |
|
121 } |
|
122 |
|
123 /** |
|
124 * Perform helper when called as $this->_helper->actionStack() from an action controller |
|
125 * |
|
126 * Proxies to {@link simple()} |
|
127 * |
|
128 * @param string $action |
|
129 * @param string $controller |
|
130 * @param string $module |
|
131 * @param array $params |
|
132 * @return boolean |
|
133 */ |
|
134 public function direct($action, $controller = null, $module = null, array $params = array()) |
|
135 { |
|
136 return $this->actionToStack($action, $controller, $module, $params); |
|
137 } |
|
138 } |