1 | <?php |
||
5 | class HttpRequest implements Request |
||
6 | { |
||
7 | protected $getParameters; |
||
8 | protected $postParameters; |
||
9 | protected $server; |
||
10 | protected $files; |
||
11 | protected $cookies; |
||
12 | protected $inputStream; |
||
13 | |||
14 | public function __construct( |
||
15 | array $get, |
||
16 | array $post, |
||
17 | array $cookies, |
||
18 | array $files, |
||
19 | array $server, |
||
20 | $inputStream = '' |
||
21 | ) { |
||
22 | $this->getParameters = $get; |
||
23 | $this->postParameters = $post; |
||
24 | $this->cookies = $cookies; |
||
25 | $this->files = $files; |
||
26 | $this->server = $server; |
||
27 | $this->inputStream = $inputStream; |
||
28 | |||
29 | $this->parseInputParameters(); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Returns a parameter value or a default value if none is set. |
||
34 | * |
||
35 | * @param string $key |
||
36 | * @param string $defaultValue (optional) |
||
37 | * @return string |
||
38 | */ |
||
39 | public function getParameter($key, $defaultValue = null) |
||
51 | |||
52 | /** |
||
53 | * Returns a query parameter value or a default value if none is set. |
||
54 | * |
||
55 | * @param string $key |
||
56 | * @param string $defaultValue (optional) |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getQueryParameter($key, $defaultValue = null) |
||
67 | |||
68 | /** |
||
69 | * Returns a body parameter value or a default value if none is set. |
||
70 | * |
||
71 | * @param string $key |
||
72 | * @param string $defaultValue (optional) |
||
73 | * @return string |
||
74 | */ |
||
75 | public function getBodyParameter($key, $defaultValue = null) |
||
83 | |||
84 | /** |
||
85 | * Returns a file value or a default value if none is set. |
||
86 | * |
||
87 | * @param string $key |
||
88 | * @param string $defaultValue (optional) |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getFile($key, $defaultValue = null) |
||
99 | |||
100 | /** |
||
101 | * Returns a cookie value or a default value if none is set. |
||
102 | * |
||
103 | * @param string $key |
||
104 | * @param string $defaultValue (optional) |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getCookie($key, $defaultValue = null) |
||
115 | |||
116 | /** |
||
117 | * Returns all parameters. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public function getParameters() |
||
125 | |||
126 | /** |
||
127 | * Returns all query parameters. |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | public function getQueryParameters() |
||
135 | |||
136 | /** |
||
137 | * Returns all body parameters. |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | public function getBodyParameters() |
||
145 | |||
146 | /** |
||
147 | * Returns raw values from the read-only stream that allows you to read raw data from the request body. |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | public function getRawBody() |
||
155 | |||
156 | /** |
||
157 | * Returns a Cookie Iterator. |
||
158 | * |
||
159 | * @return array |
||
160 | */ |
||
161 | public function getCookies() |
||
165 | |||
166 | /** |
||
167 | * Returns a File Iterator. |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | public function getFiles() |
||
175 | |||
176 | /** |
||
177 | * The URI which was given in order to access this page |
||
178 | * |
||
179 | * @return string |
||
180 | * @throws MissingRequestMetaVariableException |
||
181 | */ |
||
182 | public function getUri() |
||
186 | |||
187 | /** |
||
188 | * Return just the path |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | public function getPath() |
||
196 | |||
197 | /** |
||
198 | * Which request method was used to access the page; |
||
199 | * i.e. 'GET', 'HEAD', 'POST', 'PUT'. |
||
200 | * |
||
201 | * @return string |
||
202 | * @throws MissingRequestMetaVariableException |
||
203 | */ |
||
204 | public function getMethod() |
||
208 | |||
209 | /** |
||
210 | * Contents of the Accept: header from the current request, if there is one. |
||
211 | * |
||
212 | * @return string |
||
213 | * @throws MissingRequestMetaVariableException |
||
214 | */ |
||
215 | public function getHttpAccept() |
||
219 | |||
220 | /** |
||
221 | * The address of the page (if any) which referred the user agent to the |
||
222 | * current page. |
||
223 | * |
||
224 | * @return string |
||
225 | * @throws MissingRequestMetaVariableException |
||
226 | */ |
||
227 | public function getReferer() |
||
231 | |||
232 | /** |
||
233 | * Content of the User-Agent header from the request, if there is one. |
||
234 | * |
||
235 | * @return string |
||
236 | * @throws MissingRequestMetaVariableException |
||
237 | */ |
||
238 | public function getUserAgent() |
||
242 | |||
243 | /** |
||
244 | * The IP address from which the user is viewing the current page. |
||
245 | * |
||
246 | * @return string |
||
247 | * @throws MissingRequestMetaVariableException |
||
248 | */ |
||
249 | public function getIpAddress() |
||
253 | |||
254 | /** |
||
255 | * Checks to see whether the current request is using HTTPS. |
||
256 | * |
||
257 | * @return boolean |
||
258 | */ |
||
259 | public function isSecure() |
||
265 | |||
266 | /** |
||
267 | * The query string, if any, via which the page was accessed. |
||
268 | * |
||
269 | * @return string |
||
270 | * @throws MissingRequestMetaVariableException |
||
271 | */ |
||
272 | public function getQueryString() |
||
276 | |||
277 | private function getServerVariable($key) |
||
285 | |||
286 | private function parseInputParameters() |
||
300 | } |
||
301 |