|
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 Router |
|
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: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** Zend_Controller_Router_Interface */ |
|
25 require_once 'Zend/Controller/Router/Interface.php'; |
|
26 |
|
27 /** |
|
28 * Simple first implementation of a router, to be replaced |
|
29 * with rules-based URI processor. |
|
30 * |
|
31 * @category Zend |
|
32 * @package Zend_Controller |
|
33 * @subpackage Router |
|
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
36 */ |
|
37 abstract class Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface |
|
38 { |
|
39 /** |
|
40 * Front controller instance |
|
41 * @var Zend_Controller_Front |
|
42 */ |
|
43 protected $_frontController; |
|
44 |
|
45 /** |
|
46 * Array of invocation parameters to use when instantiating action |
|
47 * controllers |
|
48 * @var array |
|
49 */ |
|
50 protected $_invokeParams = array(); |
|
51 |
|
52 /** |
|
53 * Constructor |
|
54 * |
|
55 * @param array $params |
|
56 * @return void |
|
57 */ |
|
58 public function __construct(array $params = array()) |
|
59 { |
|
60 $this->setParams($params); |
|
61 } |
|
62 |
|
63 /** |
|
64 * Add or modify a parameter to use when instantiating an action controller |
|
65 * |
|
66 * @param string $name |
|
67 * @param mixed $value |
|
68 * @return Zend_Controller_Router |
|
69 */ |
|
70 public function setParam($name, $value) |
|
71 { |
|
72 $name = (string) $name; |
|
73 $this->_invokeParams[$name] = $value; |
|
74 return $this; |
|
75 } |
|
76 |
|
77 /** |
|
78 * Set parameters to pass to action controller constructors |
|
79 * |
|
80 * @param array $params |
|
81 * @return Zend_Controller_Router |
|
82 */ |
|
83 public function setParams(array $params) |
|
84 { |
|
85 $this->_invokeParams = array_merge($this->_invokeParams, $params); |
|
86 return $this; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Retrieve a single parameter from the controller parameter stack |
|
91 * |
|
92 * @param string $name |
|
93 * @return mixed |
|
94 */ |
|
95 public function getParam($name) |
|
96 { |
|
97 if(isset($this->_invokeParams[$name])) { |
|
98 return $this->_invokeParams[$name]; |
|
99 } |
|
100 |
|
101 return null; |
|
102 } |
|
103 |
|
104 /** |
|
105 * Retrieve action controller instantiation parameters |
|
106 * |
|
107 * @return array |
|
108 */ |
|
109 public function getParams() |
|
110 { |
|
111 return $this->_invokeParams; |
|
112 } |
|
113 |
|
114 /** |
|
115 * Clear the controller parameter stack |
|
116 * |
|
117 * By default, clears all parameters. If a parameter name is given, clears |
|
118 * only that parameter; if an array of parameter names is provided, clears |
|
119 * each. |
|
120 * |
|
121 * @param null|string|array single key or array of keys for params to clear |
|
122 * @return Zend_Controller_Router |
|
123 */ |
|
124 public function clearParams($name = null) |
|
125 { |
|
126 if (null === $name) { |
|
127 $this->_invokeParams = array(); |
|
128 } elseif (is_string($name) && isset($this->_invokeParams[$name])) { |
|
129 unset($this->_invokeParams[$name]); |
|
130 } elseif (is_array($name)) { |
|
131 foreach ($name as $key) { |
|
132 if (is_string($key) && isset($this->_invokeParams[$key])) { |
|
133 unset($this->_invokeParams[$key]); |
|
134 } |
|
135 } |
|
136 } |
|
137 |
|
138 return $this; |
|
139 } |
|
140 |
|
141 /** |
|
142 * Retrieve Front Controller |
|
143 * |
|
144 * @return Zend_Controller_Front |
|
145 */ |
|
146 public function getFrontController() |
|
147 { |
|
148 // Used cache version if found |
|
149 if (null !== $this->_frontController) { |
|
150 return $this->_frontController; |
|
151 } |
|
152 |
|
153 require_once 'Zend/Controller/Front.php'; |
|
154 $this->_frontController = Zend_Controller_Front::getInstance(); |
|
155 return $this->_frontController; |
|
156 } |
|
157 |
|
158 /** |
|
159 * Set Front Controller |
|
160 * |
|
161 * @param Zend_Controller_Front $controller |
|
162 * @return Zend_Controller_Router_Interface |
|
163 */ |
|
164 public function setFrontController(Zend_Controller_Front $controller) |
|
165 { |
|
166 $this->_frontController = $controller; |
|
167 return $this; |
|
168 } |
|
169 |
|
170 } |