1 | <?php |
||
43 | abstract class RequestAbstract |
||
44 | { |
||
45 | /** |
||
46 | * @access protected |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $_route; |
||
50 | |||
51 | /** |
||
52 | * @access protected |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $_params = array(); |
||
56 | |||
57 | /** |
||
58 | * @access protected |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $_routeParams = array(); |
||
62 | |||
63 | /** |
||
64 | * @access protected |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $_base; |
||
68 | |||
69 | /** |
||
70 | * @access protected |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $_locale; |
||
74 | |||
75 | /** |
||
76 | * @access protected |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $_data = array(); |
||
80 | |||
81 | /** |
||
82 | * Constructs the object |
||
83 | * |
||
84 | * @access public |
||
85 | * @param string $route |
||
86 | * @param array params |
||
87 | * @param string $base |
||
88 | * @param string $locale |
||
89 | * @param array $data |
||
90 | */ |
||
91 | public function __construct($route, $params, $base, $locale, $data = array()) |
||
109 | |||
110 | /** |
||
111 | * Returns the route of the request. |
||
112 | * |
||
113 | * @access public |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getRoute() |
||
120 | |||
121 | /** |
||
122 | * Sets the route of the request |
||
123 | * |
||
124 | * @access public |
||
125 | * @param string $route |
||
126 | */ |
||
127 | public function setRoute($route) |
||
131 | |||
132 | /** |
||
133 | * Returns true if the given param key exists. |
||
134 | * |
||
135 | * @access public |
||
136 | * @param string $key |
||
137 | * @return string |
||
138 | */ |
||
139 | public function hasParam($key) |
||
143 | |||
144 | /** |
||
145 | * Returns the value for the given param key. If the |
||
146 | * key does not exists the function will return false. |
||
147 | * |
||
148 | * @access public |
||
149 | * @param string $key |
||
150 | * @return mixed |
||
151 | */ |
||
152 | public function getParam($key) |
||
153 | { |
||
154 | if (!$this->hasParam($key)) { |
||
155 | return false; |
||
156 | } |
||
157 | |||
158 | return $this->_params[$key]; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Returns all params of the request |
||
163 | * |
||
164 | * @access public |
||
165 | * @return array |
||
166 | */ |
||
167 | public function getParams() |
||
171 | |||
172 | /** |
||
173 | * Adds an parameter which is detected in the route. |
||
174 | * |
||
175 | * @access public |
||
176 | * @param mixed $param |
||
177 | */ |
||
178 | public function addRouteParam($param) |
||
182 | |||
183 | /** |
||
184 | * Sets the array of route params for the request |
||
185 | * |
||
186 | * @access public |
||
187 | * @param array $params |
||
188 | * @return boolean |
||
189 | */ |
||
190 | public function setRouteParams($params) |
||
191 | { |
||
192 | if (!is_array($params)) { |
||
193 | return false; |
||
194 | } |
||
195 | |||
196 | $this->_routeParams = $params; |
||
197 | |||
198 | return true; |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * Returns the route param for the given index. |
||
203 | * |
||
204 | * @access public |
||
205 | * @param integer $index |
||
206 | * @return string|boolean |
||
207 | */ |
||
208 | public function getRouteParam($index) |
||
209 | { |
||
210 | if (!isset($this->_routeParams[$index])) { |
||
211 | return false; |
||
212 | } |
||
213 | |||
214 | return $this->_routeParams[$index]; |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Returns the delimitier, which is used to split the route |
||
219 | * into parts. |
||
220 | * |
||
221 | * @access public |
||
222 | * @return string |
||
223 | */ |
||
224 | abstract public function getRouteDelimiter(); |
||
225 | |||
226 | /** |
||
227 | * Returns the correct url for the given url part |
||
228 | * |
||
229 | * @access public |
||
230 | * @param string $routePart |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getFullRoute($routePart = '') |
||
250 | |||
251 | /** |
||
252 | * Returns the locale of the request |
||
253 | * |
||
254 | * @access public |
||
255 | * @return string |
||
256 | */ |
||
257 | public function getLocale() |
||
261 | } |
||
262 |