1 | <?php |
||
16 | class IncomingRequest implements IHTTPRequest |
||
17 | { |
||
18 | /** |
||
19 | * The request headers. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $_headers; |
||
24 | |||
25 | /** |
||
26 | * The incoming url in raw format. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $_rawUrl = null; |
||
31 | |||
32 | /** |
||
33 | * The request method (GET, POST, PUT, DELETE or MERGE). |
||
34 | * |
||
35 | * @var HTTPRequestMethod HttpVerb |
||
36 | */ |
||
37 | private $_method; |
||
38 | |||
39 | /** |
||
40 | * The query options as key value. |
||
41 | * |
||
42 | * @var array(string, string); |
||
43 | */ |
||
44 | private $_queryOptions; |
||
45 | |||
46 | /** |
||
47 | * A collection that represents mapping between query |
||
48 | * option and its count. |
||
49 | * |
||
50 | * @var array(string, int) |
||
51 | */ |
||
52 | private $_queryOptionsCount; |
||
53 | |||
54 | /** |
||
55 | * Initialize a new instance of IncomingWebRequestContext. |
||
56 | */ |
||
57 | public function __construct() |
||
65 | |||
66 | /** |
||
67 | * Get the request headers |
||
68 | * By-default we will get the following headers: |
||
69 | * HTTP_HOST |
||
70 | * HTTP_USER_AGENT |
||
71 | * HTTP_ACCEPT |
||
72 | * HTTP_ACCEPT_LANGUAGE |
||
73 | * HTTP_ACCEPT_ENCODING |
||
74 | * HTTP_ACCEPT_CHARSET |
||
75 | * HTTP_KEEP_ALIVE |
||
76 | * HTTP_CONNECTION, |
||
77 | * HTTP_CACHE_CONTROL |
||
78 | * HTTP_USER_AGENT |
||
79 | * HTTP_IF_MATCH |
||
80 | * HTTP_IF_NONE_MATCH |
||
81 | * HTTP_IF_MODIFIED |
||
82 | * HTTP_IF_MATCH |
||
83 | * HTTP_IF_NONE_MATCH |
||
84 | * HTTP_IF_UNMODIFIED_SINCE |
||
85 | * //TODO: these aren't really headers... |
||
86 | * REQUEST_URI |
||
87 | * REQUEST_METHOD |
||
88 | * REQUEST_TIME |
||
89 | * SERVER_NAME |
||
90 | * SERVER_PORT |
||
91 | * SERVER_PORT_SECURE |
||
92 | * SERVER_PROTOCOL |
||
93 | * SERVER_SOFTWARE |
||
94 | * CONTENT_TYPE |
||
95 | * CONTENT_LENGTH |
||
96 | * We may get user defined customized headers also like |
||
97 | * HTTP_DATASERVICEVERSION, HTTP_MAXDATASERVICEVERSION. |
||
98 | * |
||
99 | * @return string[] |
||
100 | */ |
||
101 | private function getHeaders() |
||
120 | |||
121 | /** |
||
122 | * get the raw incoming url. |
||
123 | * |
||
124 | * @return string RequestURI called by User with the value of QueryString |
||
125 | */ |
||
126 | public function getRawUrl() |
||
141 | |||
142 | /** |
||
143 | * get the specific request headers. |
||
144 | * |
||
145 | * @param string $key The header name |
||
146 | * |
||
147 | * @return string|null value of the header, NULL if header is absent |
||
148 | */ |
||
149 | public function getRequestHeader($key) |
||
163 | |||
164 | /** |
||
165 | * Get the QUERY_STRING |
||
166 | * Note: This method will return empty string if no query string present. |
||
167 | * |
||
168 | * @return string $_header[HttpRequestHeaderQueryString] |
||
169 | */ |
||
170 | private function getQueryString() |
||
178 | |||
179 | /** |
||
180 | * Split the QueryString and assigns them as array element in KEY=VALUE. |
||
181 | * |
||
182 | * @return string[] |
||
183 | */ |
||
184 | public function getQueryParameters() |
||
208 | |||
209 | /** |
||
210 | * Get the HTTP method |
||
211 | * Value will be set from the value of the HTTP method of the |
||
212 | * incoming Web request. |
||
213 | * |
||
214 | * @return HTTPRequestMethod $_header[HttpRequestHeaderMethod] |
||
215 | */ |
||
216 | public function getMethod() |
||
220 | |||
221 | public function getAllInput() |
||
225 | } |
||
226 |
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: