1 | <?php |
||
23 | class Context implements ControllerContextInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var ServerRequestInterface |
||
27 | */ |
||
28 | private $request; |
||
29 | |||
30 | /** |
||
31 | * @var ResponseInterface |
||
32 | */ |
||
33 | private $response; |
||
34 | |||
35 | /** |
||
36 | * @var Route |
||
37 | */ |
||
38 | private $route; |
||
39 | |||
40 | /** |
||
41 | * @var bool |
||
42 | */ |
||
43 | private $handleResponse = false; |
||
44 | |||
45 | /** |
||
46 | * @var UriGeneratorInterface |
||
47 | */ |
||
48 | private $uriGenerator; |
||
49 | |||
50 | /** |
||
51 | * Creates a controller context |
||
52 | * |
||
53 | * @param ServerRequestInterface $request |
||
54 | * @param Route $route |
||
55 | * @param UriGeneratorInterface $uriGenerator |
||
56 | */ |
||
57 | public function __construct(ServerRequestInterface $request, Route $route, UriGeneratorInterface $uriGenerator) |
||
63 | |||
64 | /** |
||
65 | * Gets the post parameter that was submitted with provided name |
||
66 | * |
||
67 | * If its not submitted the default value will be returned. |
||
68 | * If no arguments are passed the full server parameters from request will |
||
69 | * be returned. In this case the default value is ignored. |
||
70 | * |
||
71 | * @param null|string $name |
||
72 | * @param mixed $default |
||
73 | * |
||
74 | * @return array|string |
||
75 | */ |
||
76 | public function postParam($name = null, $default = null) |
||
84 | |||
85 | /** |
||
86 | * Gets the URL query parameter with provided name |
||
87 | * |
||
88 | * If its not submitted the default value will be returned. |
||
89 | * If no arguments are passed the full URL query parameters from request will |
||
90 | * be returned. In this case the default value is ignored. |
||
91 | * |
||
92 | * @param null|string $name |
||
93 | * @param mixed $default |
||
94 | * |
||
95 | * @return array|string |
||
96 | */ |
||
97 | public function queryParam($name = null, $default = null) |
||
105 | |||
106 | /** |
||
107 | * Gets the route parameter with provided name |
||
108 | * |
||
109 | * If its not submitted the default value will be returned. |
||
110 | * If no arguments are passed the full URL query parameters from request will |
||
111 | * be returned. In this case the default value is ignored. |
||
112 | * |
||
113 | * @param null|string $name |
||
114 | * @param mixed $default |
||
115 | * |
||
116 | * @return array|string |
||
117 | */ |
||
118 | public function routeParam($name = null, $default = null) |
||
122 | |||
123 | /** |
||
124 | * Sets a redirection header in the HTTP response |
||
125 | * |
||
126 | * @param string $location Location name, path or identifier |
||
127 | * @param array $options Filter options |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | public function redirect($location, array $options = []) |
||
138 | |||
139 | /** |
||
140 | * Disables response rendering |
||
141 | * |
||
142 | * @return self|ControllerContextInterface |
||
143 | */ |
||
144 | public function disableRendering() |
||
149 | |||
150 | /** |
||
151 | * Sets the view template to use by render process |
||
152 | * |
||
153 | * @param string $template |
||
154 | * |
||
155 | * @return self|ControllerContextInterface |
||
156 | */ |
||
157 | public function useTemplate($template) |
||
162 | |||
163 | /** |
||
164 | * Sets a new response |
||
165 | * |
||
166 | * @param ResponseInterface $response |
||
167 | * |
||
168 | * @return self|ControllerContextInterface |
||
169 | */ |
||
170 | public function setResponse(ResponseInterface $response) |
||
175 | |||
176 | /** |
||
177 | * Sets a new or updated server request |
||
178 | * |
||
179 | * @param ServerRequestInterface $request |
||
180 | * |
||
181 | * @return self|ControllerContextInterface |
||
182 | */ |
||
183 | public function changeRequest(ServerRequestInterface $request) |
||
188 | |||
189 | /** |
||
190 | * Get current HTTP response |
||
191 | * |
||
192 | * @return ResponseInterface |
||
193 | */ |
||
194 | public function response() |
||
198 | |||
199 | /** |
||
200 | * Get current HTTP request |
||
201 | * |
||
202 | * @return ServerRequestInterface |
||
203 | */ |
||
204 | public function request() |
||
208 | |||
209 | /** |
||
210 | * True when it handles the response |
||
211 | * |
||
212 | * @return boolean |
||
213 | */ |
||
214 | public function handlesResponse() |
||
218 | |||
219 | /** |
||
220 | * Checks the request method |
||
221 | * |
||
222 | * @param string $methodName |
||
223 | * |
||
224 | * @return boolean |
||
225 | */ |
||
226 | public function requestIs($methodName) |
||
231 | |||
232 | /** |
||
233 | * Gets the value(s) from provided data |
||
234 | * |
||
235 | * @param mixed $data |
||
236 | * @param null|string $name |
||
237 | * @param null|string $default |
||
238 | * |
||
239 | * @return mixed |
||
240 | */ |
||
241 | private function getData($data, $name = null, $default = null) |
||
254 | } |
||
255 |