|
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 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @category Zend |
|
24 * @package Zend_Controller |
|
25 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
26 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
27 */ |
|
28 abstract class Zend_Controller_Request_Abstract |
|
29 { |
|
30 /** |
|
31 * Has the action been dispatched? |
|
32 * @var boolean |
|
33 */ |
|
34 protected $_dispatched = false; |
|
35 |
|
36 /** |
|
37 * Module |
|
38 * @var string |
|
39 */ |
|
40 protected $_module; |
|
41 |
|
42 /** |
|
43 * Module key for retrieving module from params |
|
44 * @var string |
|
45 */ |
|
46 protected $_moduleKey = 'module'; |
|
47 |
|
48 /** |
|
49 * Controller |
|
50 * @var string |
|
51 */ |
|
52 protected $_controller; |
|
53 |
|
54 /** |
|
55 * Controller key for retrieving controller from params |
|
56 * @var string |
|
57 */ |
|
58 protected $_controllerKey = 'controller'; |
|
59 |
|
60 /** |
|
61 * Action |
|
62 * @var string |
|
63 */ |
|
64 protected $_action; |
|
65 |
|
66 /** |
|
67 * Action key for retrieving action from params |
|
68 * @var string |
|
69 */ |
|
70 protected $_actionKey = 'action'; |
|
71 |
|
72 /** |
|
73 * Request parameters |
|
74 * @var array |
|
75 */ |
|
76 protected $_params = array(); |
|
77 |
|
78 /** |
|
79 * Retrieve the module name |
|
80 * |
|
81 * @return string |
|
82 */ |
|
83 public function getModuleName() |
|
84 { |
|
85 if (null === $this->_module) { |
|
86 $this->_module = $this->getParam($this->getModuleKey()); |
|
87 } |
|
88 |
|
89 return $this->_module; |
|
90 } |
|
91 |
|
92 /** |
|
93 * Set the module name to use |
|
94 * |
|
95 * @param string $value |
|
96 * @return Zend_Controller_Request_Abstract |
|
97 */ |
|
98 public function setModuleName($value) |
|
99 { |
|
100 $this->_module = $value; |
|
101 return $this; |
|
102 } |
|
103 |
|
104 /** |
|
105 * Retrieve the controller name |
|
106 * |
|
107 * @return string |
|
108 */ |
|
109 public function getControllerName() |
|
110 { |
|
111 if (null === $this->_controller) { |
|
112 $this->_controller = $this->getParam($this->getControllerKey()); |
|
113 } |
|
114 |
|
115 return $this->_controller; |
|
116 } |
|
117 |
|
118 /** |
|
119 * Set the controller name to use |
|
120 * |
|
121 * @param string $value |
|
122 * @return Zend_Controller_Request_Abstract |
|
123 */ |
|
124 public function setControllerName($value) |
|
125 { |
|
126 $this->_controller = $value; |
|
127 return $this; |
|
128 } |
|
129 |
|
130 /** |
|
131 * Retrieve the action name |
|
132 * |
|
133 * @return string |
|
134 */ |
|
135 public function getActionName() |
|
136 { |
|
137 if (null === $this->_action) { |
|
138 $this->_action = $this->getParam($this->getActionKey()); |
|
139 } |
|
140 |
|
141 return $this->_action; |
|
142 } |
|
143 |
|
144 /** |
|
145 * Set the action name |
|
146 * |
|
147 * @param string $value |
|
148 * @return Zend_Controller_Request_Abstract |
|
149 */ |
|
150 public function setActionName($value) |
|
151 { |
|
152 $this->_action = $value; |
|
153 /** |
|
154 * @see ZF-3465 |
|
155 */ |
|
156 if (null === $value) { |
|
157 $this->setParam($this->getActionKey(), $value); |
|
158 } |
|
159 return $this; |
|
160 } |
|
161 |
|
162 /** |
|
163 * Retrieve the module key |
|
164 * |
|
165 * @return string |
|
166 */ |
|
167 public function getModuleKey() |
|
168 { |
|
169 return $this->_moduleKey; |
|
170 } |
|
171 |
|
172 /** |
|
173 * Set the module key |
|
174 * |
|
175 * @param string $key |
|
176 * @return Zend_Controller_Request_Abstract |
|
177 */ |
|
178 public function setModuleKey($key) |
|
179 { |
|
180 $this->_moduleKey = (string) $key; |
|
181 return $this; |
|
182 } |
|
183 |
|
184 /** |
|
185 * Retrieve the controller key |
|
186 * |
|
187 * @return string |
|
188 */ |
|
189 public function getControllerKey() |
|
190 { |
|
191 return $this->_controllerKey; |
|
192 } |
|
193 |
|
194 /** |
|
195 * Set the controller key |
|
196 * |
|
197 * @param string $key |
|
198 * @return Zend_Controller_Request_Abstract |
|
199 */ |
|
200 public function setControllerKey($key) |
|
201 { |
|
202 $this->_controllerKey = (string) $key; |
|
203 return $this; |
|
204 } |
|
205 |
|
206 /** |
|
207 * Retrieve the action key |
|
208 * |
|
209 * @return string |
|
210 */ |
|
211 public function getActionKey() |
|
212 { |
|
213 return $this->_actionKey; |
|
214 } |
|
215 |
|
216 /** |
|
217 * Set the action key |
|
218 * |
|
219 * @param string $key |
|
220 * @return Zend_Controller_Request_Abstract |
|
221 */ |
|
222 public function setActionKey($key) |
|
223 { |
|
224 $this->_actionKey = (string) $key; |
|
225 return $this; |
|
226 } |
|
227 |
|
228 /** |
|
229 * Get an action parameter |
|
230 * |
|
231 * @param string $key |
|
232 * @param mixed $default Default value to use if key not found |
|
233 * @return mixed |
|
234 */ |
|
235 public function getParam($key, $default = null) |
|
236 { |
|
237 $key = (string) $key; |
|
238 if (isset($this->_params[$key])) { |
|
239 return $this->_params[$key]; |
|
240 } |
|
241 |
|
242 return $default; |
|
243 } |
|
244 |
|
245 /** |
|
246 * Retrieve only user params (i.e, any param specific to the object and not the environment) |
|
247 * |
|
248 * @return array |
|
249 */ |
|
250 public function getUserParams() |
|
251 { |
|
252 return $this->_params; |
|
253 } |
|
254 |
|
255 /** |
|
256 * Retrieve a single user param (i.e, a param specific to the object and not the environment) |
|
257 * |
|
258 * @param string $key |
|
259 * @param string $default Default value to use if key not found |
|
260 * @return mixed |
|
261 */ |
|
262 public function getUserParam($key, $default = null) |
|
263 { |
|
264 if (isset($this->_params[$key])) { |
|
265 return $this->_params[$key]; |
|
266 } |
|
267 |
|
268 return $default; |
|
269 } |
|
270 |
|
271 /** |
|
272 * Set an action parameter |
|
273 * |
|
274 * A $value of null will unset the $key if it exists |
|
275 * |
|
276 * @param string $key |
|
277 * @param mixed $value |
|
278 * @return Zend_Controller_Request_Abstract |
|
279 */ |
|
280 public function setParam($key, $value) |
|
281 { |
|
282 $key = (string) $key; |
|
283 |
|
284 if ((null === $value) && isset($this->_params[$key])) { |
|
285 unset($this->_params[$key]); |
|
286 } elseif (null !== $value) { |
|
287 $this->_params[$key] = $value; |
|
288 } |
|
289 |
|
290 return $this; |
|
291 } |
|
292 |
|
293 /** |
|
294 * Get all action parameters |
|
295 * |
|
296 * @return array |
|
297 */ |
|
298 public function getParams() |
|
299 { |
|
300 return $this->_params; |
|
301 } |
|
302 |
|
303 /** |
|
304 * Set action parameters en masse; does not overwrite |
|
305 * |
|
306 * Null values will unset the associated key. |
|
307 * |
|
308 * @param array $array |
|
309 * @return Zend_Controller_Request_Abstract |
|
310 */ |
|
311 public function setParams(array $array) |
|
312 { |
|
313 $this->_params = $this->_params + (array) $array; |
|
314 |
|
315 foreach ($this->_params as $key => $value) { |
|
316 if (null === $value) { |
|
317 unset($this->_params[$key]); |
|
318 } |
|
319 } |
|
320 |
|
321 return $this; |
|
322 } |
|
323 |
|
324 /** |
|
325 * Unset all user parameters |
|
326 * |
|
327 * @return Zend_Controller_Request_Abstract |
|
328 */ |
|
329 public function clearParams() |
|
330 { |
|
331 $this->_params = array(); |
|
332 return $this; |
|
333 } |
|
334 |
|
335 /** |
|
336 * Set flag indicating whether or not request has been dispatched |
|
337 * |
|
338 * @param boolean $flag |
|
339 * @return Zend_Controller_Request_Abstract |
|
340 */ |
|
341 public function setDispatched($flag = true) |
|
342 { |
|
343 $this->_dispatched = $flag ? true : false; |
|
344 return $this; |
|
345 } |
|
346 |
|
347 /** |
|
348 * Determine if the request has been dispatched |
|
349 * |
|
350 * @return boolean |
|
351 */ |
|
352 public function isDispatched() |
|
353 { |
|
354 return $this->_dispatched; |
|
355 } |
|
356 } |