"Fossies" - the Fresh Open Source Software Archive 
Member "icingaweb2-2.11.4/library/vendor/Zend/Controller/Dispatcher/Abstract.php" (26 Jan 2023, 11549 Bytes) of package /linux/www/icingaweb2-2.11.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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 Dispatcher
18 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id$
21 */
22
23 /** Zend_Controller_Dispatcher_Interface */
24
25 /**
26 * @category Zend
27 * @package Zend_Controller
28 * @subpackage Dispatcher
29 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
30 * @license http://framework.zend.com/license/new-bsd New BSD License
31 */
32 abstract class Zend_Controller_Dispatcher_Abstract implements Zend_Controller_Dispatcher_Interface
33 {
34 /**
35 * Default action
36 * @var string
37 */
38 protected $_defaultAction = 'index';
39
40 /**
41 * Default controller
42 * @var string
43 */
44 protected $_defaultController = 'index';
45
46 /**
47 * Default module
48 * @var string
49 */
50 protected $_defaultModule = 'default';
51
52 /**
53 * Front Controller instance
54 * @var Zend_Controller_Front
55 */
56 protected $_frontController;
57
58 /**
59 * Array of invocation parameters to use when instantiating action
60 * controllers
61 * @var array
62 */
63 protected $_invokeParams = array();
64
65 /**
66 * Path delimiter character
67 * @var string
68 */
69 protected $_pathDelimiter = '_';
70
71 /**
72 * Response object to pass to action controllers, if any
73 * @var Zend_Controller_Response_Abstract|null
74 */
75 protected $_response = null;
76
77 /**
78 * Word delimiter characters
79 * @var array
80 */
81 protected $_wordDelimiter = array('-', '.');
82
83 /**
84 * Constructor
85 *
86 * @return void
87 */
88 public function __construct(array $params = array())
89 {
90 $this->setParams($params);
91 }
92
93 /**
94 * Formats a string into a controller name. This is used to take a raw
95 * controller name, such as one stored inside a Zend_Controller_Request_Abstract
96 * object, and reformat it to a proper class name that a class extending
97 * Zend_Controller_Action would use.
98 *
99 * @param string $unformatted
100 * @return string
101 */
102 public function formatControllerName($unformatted)
103 {
104 return ucfirst($this->_formatName($unformatted)) . 'Controller';
105 }
106
107 /**
108 * Formats a string into an action name. This is used to take a raw
109 * action name, such as one that would be stored inside a Zend_Controller_Request_Abstract
110 * object, and reformat into a proper method name that would be found
111 * inside a class extending Zend_Controller_Action.
112 *
113 * @param string $unformatted
114 * @return string
115 */
116 public function formatActionName($unformatted)
117 {
118 $formatted = $this->_formatName($unformatted, true);
119 return strtolower(substr($formatted, 0, 1)) . substr($formatted, 1) . 'Action';
120 }
121
122 /**
123 * Verify delimiter
124 *
125 * Verify a delimiter to use in controllers or actions. May be a single
126 * string or an array of strings.
127 *
128 * @param string|array $spec
129 * @return array
130 * @throws Zend_Controller_Dispatcher_Exception with invalid delimiters
131 */
132 public function _verifyDelimiter($spec)
133 {
134 if (is_string($spec)) {
135 return (array) $spec;
136 } elseif (is_array($spec)) {
137 $allStrings = true;
138 foreach ($spec as $delim) {
139 if (!is_string($delim)) {
140 $allStrings = false;
141 break;
142 }
143 }
144
145 if (!$allStrings) {
146 throw new Zend_Controller_Dispatcher_Exception('Word delimiter array must contain only strings');
147 }
148
149 return $spec;
150 }
151
152 throw new Zend_Controller_Dispatcher_Exception('Invalid word delimiter');
153 }
154
155 /**
156 * Retrieve the word delimiter character(s) used in
157 * controller or action names
158 *
159 * @return array
160 */
161 public function getWordDelimiter()
162 {
163 return $this->_wordDelimiter;
164 }
165
166 /**
167 * Set word delimiter
168 *
169 * Set the word delimiter to use in controllers and actions. May be a
170 * single string or an array of strings.
171 *
172 * @param string|array $spec
173 * @return Zend_Controller_Dispatcher_Abstract
174 */
175 public function setWordDelimiter($spec)
176 {
177 $spec = $this->_verifyDelimiter($spec);
178 $this->_wordDelimiter = $spec;
179
180 return $this;
181 }
182
183 /**
184 * Retrieve the path delimiter character(s) used in
185 * controller names
186 *
187 * @return array
188 */
189 public function getPathDelimiter()
190 {
191 return $this->_pathDelimiter;
192 }
193
194 /**
195 * Set path delimiter
196 *
197 * Set the path delimiter to use in controllers. May be a single string or
198 * an array of strings.
199 *
200 * @param string $spec
201 * @return Zend_Controller_Dispatcher_Abstract
202 */
203 public function setPathDelimiter($spec)
204 {
205 if (!is_string($spec)) {
206 throw new Zend_Controller_Dispatcher_Exception('Invalid path delimiter');
207 }
208 $this->_pathDelimiter = $spec;
209
210 return $this;
211 }
212
213 /**
214 * Formats a string from a URI into a PHP-friendly name.
215 *
216 * By default, replaces words separated by the word separator character(s)
217 * with camelCaps. If $isAction is false, it also preserves replaces words
218 * separated by the path separation character with an underscore, making
219 * the following word Title cased. All non-alphanumeric characters are
220 * removed.
221 *
222 * @param string $unformatted
223 * @param boolean $isAction Defaults to false
224 * @return string
225 */
226 protected function _formatName($unformatted, $isAction = false)
227 {
228 // preserve directories
229 if (!$isAction) {
230 $segments = explode($this->getPathDelimiter(), $unformatted);
231 } else {
232 $segments = (array) $unformatted;
233 }
234
235 foreach ($segments as $key => $segment) {
236 $segment = str_replace($this->getWordDelimiter(), ' ', strtolower($segment));
237 $segment = preg_replace('/[^a-z0-9 ]/', '', $segment);
238 $segments[$key] = str_replace(' ', '', ucwords($segment));
239 }
240
241 return implode('_', $segments);
242 }
243
244 /**
245 * Retrieve front controller instance
246 *
247 * @return Zend_Controller_Front
248 */
249 public function getFrontController()
250 {
251 if (null === $this->_frontController) {
252 $this->_frontController = Zend_Controller_Front::getInstance();
253 }
254
255 return $this->_frontController;
256 }
257
258 /**
259 * Set front controller instance
260 *
261 * @param Zend_Controller_Front $controller
262 * @return Zend_Controller_Dispatcher_Abstract
263 */
264 public function setFrontController(Zend_Controller_Front $controller)
265 {
266 $this->_frontController = $controller;
267 return $this;
268 }
269
270 /**
271 * Add or modify a parameter to use when instantiating an action controller
272 *
273 * @param string $name
274 * @param mixed $value
275 * @return Zend_Controller_Dispatcher_Abstract
276 */
277 public function setParam($name, $value)
278 {
279 $name = (string) $name;
280 $this->_invokeParams[$name] = $value;
281 return $this;
282 }
283
284 /**
285 * Set parameters to pass to action controller constructors
286 *
287 * @param array $params
288 * @return Zend_Controller_Dispatcher_Abstract
289 */
290 public function setParams(array $params)
291 {
292 $this->_invokeParams = array_merge($this->_invokeParams, $params);
293 return $this;
294 }
295
296 /**
297 * Retrieve a single parameter from the controller parameter stack
298 *
299 * @param string $name
300 * @return mixed
301 */
302 public function getParam($name)
303 {
304 if(isset($this->_invokeParams[$name])) {
305 return $this->_invokeParams[$name];
306 }
307
308 return null;
309 }
310
311 /**
312 * Retrieve action controller instantiation parameters
313 *
314 * @return array
315 */
316 public function getParams()
317 {
318 return $this->_invokeParams;
319 }
320
321 /**
322 * Clear the controller parameter stack
323 *
324 * By default, clears all parameters. If a parameter name is given, clears
325 * only that parameter; if an array of parameter names is provided, clears
326 * each.
327 *
328 * @param null|string|array single key or array of keys for params to clear
329 * @return Zend_Controller_Dispatcher_Abstract
330 */
331 public function clearParams($name = null)
332 {
333 if (null === $name) {
334 $this->_invokeParams = array();
335 } elseif (is_string($name) && isset($this->_invokeParams[$name])) {
336 unset($this->_invokeParams[$name]);
337 } elseif (is_array($name)) {
338 foreach ($name as $key) {
339 if (is_string($key) && isset($this->_invokeParams[$key])) {
340 unset($this->_invokeParams[$key]);
341 }
342 }
343 }
344
345 return $this;
346 }
347
348 /**
349 * Set response object to pass to action controllers
350 *
351 * @param Zend_Controller_Response_Abstract|null $response
352 * @return Zend_Controller_Dispatcher_Abstract
353 */
354 public function setResponse(Zend_Controller_Response_Abstract $response = null)
355 {
356 $this->_response = $response;
357 return $this;
358 }
359
360 /**
361 * Return the registered response object
362 *
363 * @return Zend_Controller_Response_Abstract|null
364 */
365 public function getResponse()
366 {
367 return $this->_response;
368 }
369
370 /**
371 * Set the default controller (minus any formatting)
372 *
373 * @param string $controller
374 * @return Zend_Controller_Dispatcher_Abstract
375 */
376 public function setDefaultControllerName($controller)
377 {
378 $this->_defaultController = (string) $controller;
379 return $this;
380 }
381
382 /**
383 * Retrieve the default controller name (minus formatting)
384 *
385 * @return string
386 */
387 public function getDefaultControllerName()
388 {
389 return $this->_defaultController;
390 }
391
392 /**
393 * Set the default action (minus any formatting)
394 *
395 * @param string $action
396 * @return Zend_Controller_Dispatcher_Abstract
397 */
398 public function setDefaultAction($action)
399 {
400 $this->_defaultAction = (string) $action;
401 return $this;
402 }
403
404 /**
405 * Retrieve the default action name (minus formatting)
406 *
407 * @return string
408 */
409 public function getDefaultAction()
410 {
411 return $this->_defaultAction;
412 }
413
414 /**
415 * Set the default module
416 *
417 * @param string $module
418 * @return Zend_Controller_Dispatcher_Abstract
419 */
420 public function setDefaultModule($module)
421 {
422 $this->_defaultModule = (string) $module;
423 return $this;
424 }
425
426 /**
427 * Retrieve the default module
428 *
429 * @return string
430 */
431 public function getDefaultModule()
432 {
433 return $this->_defaultModule;
434 }
435 }