1 | <?php /** MicroRequest */ |
||
17 | class Request implements IRequest |
||
18 | { |
||
19 | /** @var bool $cli Is running as CLI */ |
||
20 | protected $cli; |
||
21 | /** @var array $data Data from request */ |
||
22 | protected $data; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * Constructor Request |
||
27 | * |
||
28 | * @access public |
||
29 | * |
||
30 | * @result void |
||
31 | */ |
||
32 | public function __construct() |
||
36 | |||
37 | /** |
||
38 | * @inheritdoc |
||
39 | */ |
||
40 | public function isCli() |
||
44 | |||
45 | /** |
||
46 | * @inheritdoc |
||
47 | */ |
||
48 | public function isAjax() |
||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | public function getMethod() |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function getUserIP() |
||
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | public function getBrowser($agent = null) |
||
76 | |||
77 | /** |
||
78 | * @inheritdoc |
||
79 | */ |
||
80 | public function getArguments() |
||
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | public function getFiles($className = '\Micro\web\Uploader') |
||
98 | |||
99 | /** |
||
100 | * @inheritdoc |
||
101 | */ |
||
102 | public function getStorage($name) |
||
106 | |||
107 | /** |
||
108 | * @inheritdoc |
||
109 | */ |
||
110 | public function setStorage($name, array $data = []) |
||
114 | |||
115 | /** |
||
116 | * @inheritdoc |
||
117 | */ |
||
118 | public function query($name) |
||
122 | |||
123 | /** |
||
124 | * @inheritdoc |
||
125 | */ |
||
126 | public function getVar($name, $storage) |
||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | public function post($name) |
||
138 | |||
139 | /** |
||
140 | * @inheritdoc |
||
141 | */ |
||
142 | public function cookie($name) |
||
146 | |||
147 | /** |
||
148 | * @inheritdoc |
||
149 | */ |
||
150 | public function session($name) |
||
154 | |||
155 | /** |
||
156 | * Get value by key from server storage |
||
157 | * |
||
158 | * @access public |
||
159 | * |
||
160 | * @param string $name Key name |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | public function server($name) |
||
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | */ |
||
172 | public function setQuery($name, $value) |
||
176 | |||
177 | /** |
||
178 | * @inheritdoc |
||
179 | */ |
||
180 | public function setVar($name, $value, $storage) |
||
184 | |||
185 | /** |
||
186 | * @inheritdoc |
||
187 | */ |
||
188 | public function setPost($name, $value) |
||
192 | |||
193 | /** |
||
194 | * @inheritdoc |
||
195 | */ |
||
196 | public function setCookie($name, $value) |
||
200 | |||
201 | /** |
||
202 | * @inheritdoc |
||
203 | */ |
||
204 | public function setSession($name, $value) |
||
208 | |||
209 | /** |
||
210 | * @inheritdoc |
||
211 | */ |
||
212 | public function unsetQuery($name) |
||
216 | |||
217 | /** |
||
218 | * @inheritdoc |
||
219 | */ |
||
220 | public function unsetVar($name, $storage) |
||
224 | |||
225 | /** |
||
226 | * @inheritdoc |
||
227 | */ |
||
228 | public function unsetPost($name) |
||
232 | |||
233 | /** |
||
234 | * @inheritdoc |
||
235 | */ |
||
236 | public function unsetSession($name) |
||
240 | |||
241 | /** |
||
242 | * @inheritdoc |
||
243 | */ |
||
244 | public function getRequestPayload() |
||
248 | } |
||
249 |
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: