1 | <?php |
||
13 | class Request |
||
14 | { |
||
15 | use \Nkey\Caribu\Mvc\Util\RequestParser; |
||
16 | |||
17 | /** |
||
18 | * Address of remote host |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | private $remoteHost; |
||
23 | |||
24 | /** |
||
25 | * Original request uri |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $origin = null; |
||
30 | |||
31 | /** |
||
32 | * Controller requested |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $controller = null; |
||
37 | |||
38 | /** |
||
39 | * Action requested |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $action = null; |
||
44 | |||
45 | /** |
||
46 | * Parameters of the request |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | private $params = array(); |
||
51 | |||
52 | /** |
||
53 | * Prefix of the uri inside application context |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | private $contextPrefix = null; |
||
58 | |||
59 | /** |
||
60 | * An occured exception |
||
61 | * |
||
62 | * @var \Exception |
||
63 | */ |
||
64 | private $exception; |
||
65 | |||
66 | /** |
||
67 | * Create a new instance of request |
||
68 | * |
||
69 | * @param string $defaultController |
||
70 | * The name of default controller of nothing is provided |
||
71 | * @param string $defaultAction |
||
72 | * The name of default action if nothing is provided |
||
73 | */ |
||
74 | 27 | private function __construct($defaultController, $defaultAction) |
|
79 | |||
80 | /** |
||
81 | * Parse an uri into its request parts |
||
82 | * |
||
83 | * @param string $uri |
||
84 | * The uri to parse |
||
85 | * |
||
86 | * @param array $serverVars |
||
87 | * The variables provided by sapi |
||
88 | * |
||
89 | * @param string $defaultController |
||
90 | * The name of the default controller if nothing else is requested |
||
91 | * |
||
92 | * @param string $defaultAction |
||
93 | * The name of the default action if nothing else is requested |
||
94 | * |
||
95 | * @return \Nkey\Caribu\Mvc\Controller\Request The new created request |
||
96 | */ |
||
97 | 27 | public static function parse($uri, $serverVars = array(), $defaultController = 'Index', $defaultAction = 'index') |
|
134 | |||
135 | /** |
||
136 | * Parse uri directly from request uri |
||
137 | * |
||
138 | * @param array $serverVars |
||
139 | * The server variables provided by sapi |
||
140 | * @param string $defaultController The |
||
141 | * name of the default controller |
||
142 | * @param string $defaultAction The |
||
143 | * name of the default action |
||
144 | * |
||
145 | * @return \Nkey\Caribu\Mvc\Controller\Request |
||
146 | * |
||
147 | * @throws InvalidUrlException If no uri exists (e.g. sapi = cli) |
||
148 | */ |
||
149 | 7 | public static function parseFromServerRequest($serverVars, $defaultController = 'Index', $defaultAction = 'index') |
|
156 | |||
157 | /** |
||
158 | * The origin uri |
||
159 | * |
||
160 | * @return string The original request string |
||
161 | */ |
||
162 | 4 | public function getOrigin() |
|
166 | |||
167 | /** |
||
168 | * The requested controller |
||
169 | * |
||
170 | * @return string The controller |
||
171 | */ |
||
172 | 24 | public function getController() |
|
176 | |||
177 | /** |
||
178 | * Set controller property |
||
179 | * |
||
180 | * @param string $controller |
||
181 | */ |
||
182 | 23 | public function setController($controller) |
|
186 | |||
187 | /** |
||
188 | * The requested action |
||
189 | * |
||
190 | * @return string The action |
||
191 | */ |
||
192 | 24 | public function getAction() |
|
196 | |||
197 | /** |
||
198 | * Set action property |
||
199 | * |
||
200 | * @param string $action |
||
201 | */ |
||
202 | 21 | public function setAction($action) |
|
206 | |||
207 | /** |
||
208 | * Retrieve the request parameters |
||
209 | * |
||
210 | * @return array The request parameters |
||
211 | */ |
||
212 | 6 | public function getParams() |
|
216 | |||
217 | /** |
||
218 | * Retrieve the context prefix |
||
219 | * |
||
220 | * @return string The context prefix |
||
221 | */ |
||
222 | 27 | public function getContextPrefix() |
|
226 | |||
227 | /** |
||
228 | * Set context prefix property |
||
229 | * |
||
230 | * @param string $prefix |
||
231 | */ |
||
232 | 5 | public function setContextPrefix($prefix) |
|
236 | |||
237 | /** |
||
238 | * Retrieve the remote host |
||
239 | * |
||
240 | * @return string The remote host address |
||
241 | */ |
||
242 | 25 | public function getRemoteHost() |
|
246 | |||
247 | /** |
||
248 | * Check whether a given parameter exists |
||
249 | * |
||
250 | * @param string $name |
||
251 | * The name of the parameter |
||
252 | * @return boolean true in case of it exists, false otherwise |
||
253 | */ |
||
254 | 1 | public function hasParam($name) |
|
258 | |||
259 | /** |
||
260 | * Get value of particular parameter |
||
261 | * |
||
262 | * @param string $name |
||
263 | * The name of parameters |
||
264 | * @param string $typeOf |
||
265 | * The type expected parameter value |
||
266 | * @return mixed Depending on $typeOf the value as requested type and escaped |
||
267 | */ |
||
268 | 1 | public function getParam($name, $typeOf = 'string') |
|
295 | |||
296 | /** |
||
297 | * To override a given parameter |
||
298 | * |
||
299 | * @param string $name |
||
300 | * The parameter name to override |
||
301 | * @param string $value |
||
302 | * The value to override |
||
303 | * |
||
304 | * @return Request the current request as fluent interface |
||
305 | */ |
||
306 | 7 | public function setParam($name, $value) |
|
311 | |||
312 | /** |
||
313 | * Set the exception occured |
||
314 | * |
||
315 | * @param \Exception $ex |
||
316 | * |
||
317 | * @return Request the current request instance |
||
318 | */ |
||
319 | 1 | public function setException(\Exception $ex) |
|
324 | |||
325 | /** |
||
326 | * Get the exception occured |
||
327 | * |
||
328 | * @return \Exception |
||
329 | */ |
||
330 | 1 | public function getException() |
|
334 | } |
||
335 |