1 | <?php |
||
5 | class HttpRequest implements Request |
||
6 | { |
||
7 | protected $getParameters; |
||
8 | protected $postParameters; |
||
9 | protected $server; |
||
10 | protected $files; |
||
11 | protected $cookies; |
||
12 | |||
13 | public function __construct( |
||
28 | |||
29 | /** |
||
30 | * Returns a parameter value or a default value if none is set. |
||
31 | * |
||
32 | * @param string $key |
||
33 | * @param string $defaultValue (optional) |
||
34 | * @return string |
||
35 | */ |
||
36 | public function getParameter($key, $defaultValue = null) |
||
48 | |||
49 | /** |
||
50 | * Returns a query parameter value or a default value if none is set. |
||
51 | * |
||
52 | * @param string $key |
||
53 | * @param string $defaultValue (optional) |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getQueryParameter($key, $defaultValue = null) |
||
64 | |||
65 | /** |
||
66 | * Returns a body parameter value or a default value if none is set. |
||
67 | * |
||
68 | * @param string $key |
||
69 | * @param string $defaultValue (optional) |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getBodyParameter($key, $defaultValue = null) |
||
80 | |||
81 | /** |
||
82 | * Returns a file value or a default value if none is set. |
||
83 | * |
||
84 | * @param string $key |
||
85 | * @param string $defaultValue (optional) |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getFile($key, $defaultValue = null) |
||
96 | |||
97 | /** |
||
98 | * Returns a cookie value or a default value if none is set. |
||
99 | * |
||
100 | * @param string $key |
||
101 | * @param string $defaultValue (optional) |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getCookie($key, $defaultValue = null) |
||
112 | |||
113 | /** |
||
114 | * Returns all parameters. |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | public function getParameters() |
||
122 | |||
123 | /** |
||
124 | * Returns all query parameters. |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | public function getQueryParameters() |
||
132 | |||
133 | /** |
||
134 | * Returns all body parameters. |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getBodyParameters() |
||
142 | |||
143 | /** |
||
144 | * Returns raw values from the read-only stream that allows you to read raw data from the request body. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getRawBody() |
||
149 | { |
||
150 | return $this->inputStream; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Returns a Cookie Iterator. |
||
155 | * |
||
156 | * @return array |
||
157 | */ |
||
158 | public function getCookies() |
||
162 | |||
163 | /** |
||
164 | * Returns a File Iterator. |
||
165 | * |
||
166 | * @return array |
||
167 | */ |
||
168 | public function getFiles() |
||
172 | |||
173 | /** |
||
174 | * The URI which was given in order to access this page |
||
175 | * |
||
176 | * @return string |
||
177 | * @throws MissingRequestMetaVariableException |
||
178 | */ |
||
179 | public function getUri() |
||
183 | |||
184 | /** |
||
185 | * Return just the path |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | public function getPath() |
||
193 | |||
194 | /** |
||
195 | * Which request method was used to access the page; |
||
196 | * i.e. 'GET', 'HEAD', 'POST', 'PUT'. |
||
197 | * |
||
198 | * @return string |
||
199 | * @throws MissingRequestMetaVariableException |
||
200 | */ |
||
201 | public function getMethod() |
||
205 | |||
206 | /** |
||
207 | * Contents of the Accept: header from the current request, if there is one. |
||
208 | * |
||
209 | * @return string |
||
210 | * @throws MissingRequestMetaVariableException |
||
211 | */ |
||
212 | public function getHttpAccept() |
||
216 | |||
217 | /** |
||
218 | * The address of the page (if any) which referred the user agent to the |
||
219 | * current page. |
||
220 | * |
||
221 | * @return string |
||
222 | * @throws MissingRequestMetaVariableException |
||
223 | */ |
||
224 | public function getReferer() |
||
228 | |||
229 | /** |
||
230 | * Content of the User-Agent header from the request, if there is one. |
||
231 | * |
||
232 | * @return string |
||
233 | * @throws MissingRequestMetaVariableException |
||
234 | */ |
||
235 | public function getUserAgent() |
||
239 | |||
240 | /** |
||
241 | * The IP address from which the user is viewing the current page. |
||
242 | * |
||
243 | * @return string |
||
244 | * @throws MissingRequestMetaVariableException |
||
245 | */ |
||
246 | public function getIpAddress() |
||
250 | |||
251 | /** |
||
252 | * Checks to see whether the current request is using HTTPS. |
||
253 | * |
||
254 | * @return boolean |
||
255 | */ |
||
256 | public function isSecure() |
||
262 | |||
263 | /** |
||
264 | * The query string, if any, via which the page was accessed. |
||
265 | * |
||
266 | * @return string |
||
267 | * @throws MissingRequestMetaVariableException |
||
268 | */ |
||
269 | public function getQueryString() |
||
273 | |||
274 | private function getServerVariable($key) |
||
282 | } |
||
283 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: