1 | <?php /** MicroRequest */ |
||
17 | class Request implements IRequest |
||
18 | { |
||
19 | /** @var bool $cli Is running as CLI */ |
||
20 | protected $cli; |
||
21 | /** @var array $files $_FILES from request */ |
||
22 | protected $files; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * Constructor Request |
||
27 | * |
||
28 | * @access public |
||
29 | * |
||
30 | * @param array $files |
||
31 | * |
||
32 | * @result void |
||
33 | */ |
||
34 | public function __construct(array $files = []) |
||
40 | |||
41 | /** |
||
42 | * Get flag of running as CLI |
||
43 | * |
||
44 | * @access public |
||
45 | * |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function isCli() |
||
52 | |||
53 | /** |
||
54 | * Check request is AJAX ? |
||
55 | * |
||
56 | * @access public |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function isAjax() |
||
64 | |||
65 | /** |
||
66 | * Get request method |
||
67 | * |
||
68 | * @access public |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getMethod() |
||
76 | |||
77 | /** |
||
78 | * Get user IP-address |
||
79 | * |
||
80 | * @access public |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getUserIP() |
||
88 | |||
89 | /** |
||
90 | * Get browser data from user user agent string |
||
91 | * |
||
92 | * @access public |
||
93 | * |
||
94 | * @param null|string $agent User agent string |
||
95 | * |
||
96 | * @return mixed |
||
97 | */ |
||
98 | public function getBrowser($agent = null) |
||
102 | |||
103 | /** |
||
104 | * Get arguments from command line |
||
105 | * |
||
106 | * @access public |
||
107 | * |
||
108 | * @param string $char -a .. -z option char |
||
109 | * @param string $name --optionName_string |
||
110 | * @param bool|null $required Required value? |
||
111 | * |
||
112 | * @return mixed |
||
113 | */ |
||
114 | public function getOption($char = '', $name = '', $required = null) |
||
143 | |||
144 | /** |
||
145 | * Get files mapper |
||
146 | * |
||
147 | * @access public |
||
148 | * |
||
149 | * @param string $className Class name of mapper |
||
150 | * |
||
151 | * @return mixed |
||
152 | */ |
||
153 | public function getFiles($className = '\Micro\Web\Uploader') |
||
157 | |||
158 | /** |
||
159 | * Get value by key from query storage |
||
160 | * |
||
161 | * @access public |
||
162 | * |
||
163 | * @param string $name Key name |
||
164 | * @param integer $filter |
||
165 | * @param mixed $options |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function query($name, $filter = FILTER_DEFAULT, $options = null) |
||
173 | |||
174 | /** |
||
175 | * Set query by key |
||
176 | * |
||
177 | * @access public |
||
178 | * |
||
179 | * @param string $name |
||
180 | * @param string|integer $value |
||
181 | * |
||
182 | * @return void |
||
183 | */ |
||
184 | public function setQuery($name, $value) |
||
188 | |||
189 | /** |
||
190 | * Get value by key from post storage |
||
191 | * |
||
192 | * @access public |
||
193 | * |
||
194 | * @param string $name Key name |
||
195 | * @param integer $filter |
||
196 | * @param mixed $options |
||
197 | * |
||
198 | * @return mixed |
||
199 | */ |
||
200 | public function post($name, $filter = FILTER_DEFAULT, $options = null) |
||
204 | |||
205 | /** |
||
206 | * Get value by key from cookie storage |
||
207 | * |
||
208 | * @access public |
||
209 | * |
||
210 | * @param string $name Key name |
||
211 | * @param integer $filter |
||
212 | * @param mixed $options |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function cookie($name, $filter = FILTER_DEFAULT, $options = null) |
||
220 | |||
221 | /** |
||
222 | * Get value by key from session storage |
||
223 | * |
||
224 | * @access public |
||
225 | * |
||
226 | * @param string $name Key name |
||
227 | * @param integer $filter |
||
228 | * @param mixed $options |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function session($name, $filter = FILTER_DEFAULT, $options = null) |
||
236 | |||
237 | /** |
||
238 | * Unset value by key from session storage |
||
239 | * |
||
240 | * @access public |
||
241 | * |
||
242 | * @param string $name Key name |
||
243 | * |
||
244 | * @return void |
||
245 | */ |
||
246 | public function unsetSession($name) |
||
252 | |||
253 | |||
254 | /** |
||
255 | * Get value by key from server storage |
||
256 | * |
||
257 | * @access public |
||
258 | * |
||
259 | * @param string $name Key name |
||
260 | * @param integer $filter |
||
261 | * @param mixed $options |
||
262 | * |
||
263 | * @return bool |
||
264 | */ |
||
265 | public function server($name, $filter = FILTER_DEFAULT, $options = null) |
||
269 | |||
270 | /** |
||
271 | * Get RequestPayload (RAW DATA) |
||
272 | * |
||
273 | * @return string|bool |
||
274 | */ |
||
275 | public function requestPayload() |
||
279 | |||
280 | /** |
||
281 | * Set value into session storage |
||
282 | * |
||
283 | * @access public |
||
284 | * |
||
285 | * @param string $name Key name |
||
286 | * @param string $value Key value |
||
287 | * |
||
288 | * @return void |
||
289 | */ |
||
290 | public function setSession($name, $value) |
||
294 | } |
||
295 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: