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 | * Get value by key from post storage |
||
176 | * |
||
177 | * @access public |
||
178 | * |
||
179 | * @param string $name Key name |
||
180 | * @param integer $filter |
||
181 | * @param mixed $options |
||
182 | * |
||
183 | * @return mixed |
||
184 | */ |
||
185 | public function post($name, $filter = FILTER_DEFAULT, $options = null) |
||
189 | |||
190 | /** |
||
191 | * Get value by key from cookie storage |
||
192 | * |
||
193 | * @access public |
||
194 | * |
||
195 | * @param string $name Key name |
||
196 | * @param integer $filter |
||
197 | * @param mixed $options |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function cookie($name, $filter = FILTER_DEFAULT, $options = null) |
||
205 | |||
206 | /** |
||
207 | * Get value by key from session storage |
||
208 | * |
||
209 | * @access public |
||
210 | * |
||
211 | * @param string $name Key name |
||
212 | * @param integer $filter |
||
213 | * @param mixed $options |
||
214 | * |
||
215 | * @return bool |
||
216 | */ |
||
217 | public function session($name, $filter = FILTER_DEFAULT, $options = null) |
||
221 | |||
222 | /** |
||
223 | * Unset value by key from session storage |
||
224 | * |
||
225 | * @access public |
||
226 | * |
||
227 | * @param string $name Key name |
||
228 | * |
||
229 | * @return void |
||
230 | */ |
||
231 | public function unsetSession($name) |
||
237 | |||
238 | |||
239 | /** |
||
240 | * Get value by key from server storage |
||
241 | * |
||
242 | * @access public |
||
243 | * |
||
244 | * @param string $name Key name |
||
245 | * @param integer $filter |
||
246 | * @param mixed $options |
||
247 | * |
||
248 | * @return bool |
||
249 | */ |
||
250 | public function server($name, $filter = FILTER_DEFAULT, $options = null) |
||
254 | |||
255 | /** |
||
256 | * Get RequestPayload (RAW DATA) |
||
257 | * |
||
258 | * @return string|bool |
||
259 | */ |
||
260 | public function requestPayload() |
||
264 | |||
265 | /** |
||
266 | * Set value into session storage |
||
267 | * |
||
268 | * @access public |
||
269 | * |
||
270 | * @param string $name Key name |
||
271 | * @param string $value Key value |
||
272 | * |
||
273 | * @return void |
||
274 | */ |
||
275 | public function setSession($name, $value) |
||
279 | } |
||
280 |
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: