1 | <?php |
||
9 | class Request implements RequestInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $protocol_version = "1.1"; |
||
15 | |||
16 | /** |
||
17 | * @var string[][] |
||
18 | */ |
||
19 | protected $headers; |
||
20 | |||
21 | /** |
||
22 | * @var StreamInterface |
||
23 | */ |
||
24 | protected $body; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $request_target; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $method; |
||
35 | |||
36 | /** |
||
37 | * @var UriInterface |
||
38 | */ |
||
39 | protected $uri; |
||
40 | |||
41 | public function __construct($uri = null, $method = null, array $headers = []) |
||
44 | |||
45 | /** |
||
46 | * Retrieves the HTTP protocol version as a string. |
||
47 | * |
||
48 | * The string MUST contain only the HTTP version number (e.g., "1.1", "1.0"). |
||
49 | * |
||
50 | * @return string HTTP protocol version. |
||
51 | */ |
||
52 | public function getProtocolVersion() |
||
56 | |||
57 | /** |
||
58 | * Return an instance with the specified HTTP protocol version. |
||
59 | * |
||
60 | * The version string MUST contain only the HTTP version number (e.g., |
||
61 | * "1.1", "1.0"). |
||
62 | * |
||
63 | * This method MUST be implemented in such a way as to retain the |
||
64 | * immutability of the message, and MUST return an instance that has the |
||
65 | * new protocol version. |
||
66 | * |
||
67 | * @param string $version HTTP protocol version |
||
68 | * @return static |
||
69 | */ |
||
70 | public function withProtocolVersion($version) |
||
74 | |||
75 | /** |
||
76 | * Retrieves all message header values. |
||
77 | * |
||
78 | * The keys represent the header name as it will be sent over the wire, and |
||
79 | * each value is an array of strings associated with the header. |
||
80 | * |
||
81 | * // Represent the headers as a string |
||
82 | * foreach ($message->getHeaders() as $name => $values) { |
||
83 | * echo $name . ": " . implode(", ", $values); |
||
84 | * } |
||
85 | * |
||
86 | * // Emit headers iteratively: |
||
87 | * foreach ($message->getHeaders() as $name => $values) { |
||
88 | * foreach ($values as $value) { |
||
89 | * header(sprintf('%s: %s', $name, $value), false); |
||
90 | * } |
||
91 | * } |
||
92 | * |
||
93 | * While header names are not case-sensitive, getHeaders() will preserve the |
||
94 | * exact case in which headers were originally specified. |
||
95 | * |
||
96 | * @return string[][] Returns an associative array of the message's headers. Each |
||
97 | * key MUST be a header name, and each value MUST be an array of strings |
||
98 | * for that header. |
||
99 | */ |
||
100 | public function getHeaders() |
||
104 | |||
105 | /** |
||
106 | * Checks if a header exists by the given case-insensitive name. |
||
107 | * |
||
108 | * @param string $name Case-insensitive header field name. |
||
109 | * @return bool Returns true if any header names match the given header |
||
110 | * name using a case-insensitive string comparison. Returns false if |
||
111 | * no matching header name is found in the message. |
||
112 | */ |
||
113 | public function hasHeader($name) |
||
117 | |||
118 | /** |
||
119 | * Retrieves a message header value by the given case-insensitive name. |
||
120 | * |
||
121 | * This method returns an array of all the header values of the given |
||
122 | * case-insensitive header name. |
||
123 | * |
||
124 | * If the header does not appear in the message, this method MUST return an |
||
125 | * empty array. |
||
126 | * |
||
127 | * @param string $name Case-insensitive header field name. |
||
128 | * @return string[] An array of string values as provided for the given |
||
129 | * header. If the header does not appear in the message, this method MUST |
||
130 | * return an empty array. |
||
131 | */ |
||
132 | public function getHeader($name) |
||
136 | |||
137 | /** |
||
138 | * Retrieves a comma-separated string of the values for a single header. |
||
139 | * |
||
140 | * This method returns all of the header values of the given |
||
141 | * case-insensitive header name as a string concatenated together using |
||
142 | * a comma. |
||
143 | * |
||
144 | * NOTE: Not all header values may be appropriately represented using |
||
145 | * comma concatenation. For such headers, use getHeader() instead |
||
146 | * and supply your own delimiter when concatenating. |
||
147 | * |
||
148 | * If the header does not appear in the message, this method MUST return |
||
149 | * an empty string. |
||
150 | * |
||
151 | * @param string $name Case-insensitive header field name. |
||
152 | * @return string A string of values as provided for the given header |
||
153 | * concatenated together using a comma. If the header does not appear in |
||
154 | * the message, this method MUST return an empty string. |
||
155 | */ |
||
156 | public function getHeaderLine($name) |
||
160 | |||
161 | /** |
||
162 | * Return an instance with the provided value replacing the specified header. |
||
163 | * |
||
164 | * While header names are case-insensitive, the casing of the header will |
||
165 | * be preserved by this function, and returned from getHeaders(). |
||
166 | * |
||
167 | * This method MUST be implemented in such a way as to retain the |
||
168 | * immutability of the message, and MUST return an instance that has the |
||
169 | * new and/or updated header and value. |
||
170 | * |
||
171 | * @param string $name Case-insensitive header field name. |
||
172 | * @param string|string[] $value Header value(s). |
||
173 | * @return static |
||
174 | * @throws \InvalidArgumentException for invalid header names or values. |
||
175 | */ |
||
176 | public function withHeader($name, $value) |
||
180 | |||
181 | /** |
||
182 | * Return an instance with the specified header appended with the given value. |
||
183 | * |
||
184 | * Existing values for the specified header will be maintained. The new |
||
185 | * value(s) will be appended to the existing list. If the header did not |
||
186 | * exist previously, it will be added. |
||
187 | * |
||
188 | * This method MUST be implemented in such a way as to retain the |
||
189 | * immutability of the message, and MUST return an instance that has the |
||
190 | * new header and/or value. |
||
191 | * |
||
192 | * @param string $name Case-insensitive header field name to add. |
||
193 | * @param string|string[] $value Header value(s). |
||
194 | * @return static |
||
195 | * @throws \InvalidArgumentException for invalid header names or values. |
||
196 | */ |
||
197 | public function withAddedHeader($name, $value) |
||
201 | |||
202 | /** |
||
203 | * Return an instance without the specified header. |
||
204 | * |
||
205 | * Header resolution MUST be done without case-sensitivity. |
||
206 | * |
||
207 | * This method MUST be implemented in such a way as to retain the |
||
208 | * immutability of the message, and MUST return an instance that removes |
||
209 | * the named header. |
||
210 | * |
||
211 | * @param string $name Case-insensitive header field name to remove. |
||
212 | * @return static |
||
213 | */ |
||
214 | public function withoutHeader($name) |
||
218 | |||
219 | /** |
||
220 | * Gets the body of the message. |
||
221 | * |
||
222 | * @return StreamInterface Returns the body as a stream. |
||
223 | */ |
||
224 | public function getBody() |
||
228 | |||
229 | /** |
||
230 | * Return an instance with the specified message body. |
||
231 | * |
||
232 | * The body MUST be a StreamInterface object. |
||
233 | * |
||
234 | * This method MUST be implemented in such a way as to retain the |
||
235 | * immutability of the message, and MUST return a new instance that has the |
||
236 | * new body stream. |
||
237 | * |
||
238 | * @param StreamInterface $body Body. |
||
239 | * @return static |
||
240 | * @throws \InvalidArgumentException When the body is not valid. |
||
241 | */ |
||
242 | public function withBody(StreamInterface $body) |
||
246 | |||
247 | /** |
||
248 | * Retrieves the message's request target. |
||
249 | * |
||
250 | * Retrieves the message's request-target either as it will appear (for |
||
251 | * clients), as it appeared at request (for servers), or as it was |
||
252 | * specified for the instance (see withRequestTarget()). |
||
253 | * |
||
254 | * In most cases, this will be the origin-form of the composed URI, |
||
255 | * unless a value was provided to the concrete implementation (see |
||
256 | * withRequestTarget() below). |
||
257 | * |
||
258 | * If no URI is available, and no request-target has been specifically |
||
259 | * provided, this method MUST return the string "/". |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | public function getRequestTarget() |
||
267 | |||
268 | /** |
||
269 | * Return an instance with the specific request-target. |
||
270 | * |
||
271 | * If the request needs a non-origin-form request-target — e.g., for |
||
272 | * specifying an absolute-form, authority-form, or asterisk-form — |
||
273 | * this method may be used to create an instance with the specified |
||
274 | * request-target, verbatim. |
||
275 | * |
||
276 | * This method MUST be implemented in such a way as to retain the |
||
277 | * immutability of the message, and MUST return an instance that has the |
||
278 | * changed request target. |
||
279 | * |
||
280 | * @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various |
||
281 | * request-target forms allowed in request messages) |
||
282 | * @param mixed $requestTarget |
||
283 | * @return static |
||
284 | */ |
||
285 | public function withRequestTarget($requestTarget) |
||
289 | |||
290 | /** |
||
291 | * Retrieves the HTTP method of the request. |
||
292 | * |
||
293 | * @return string Returns the request method. |
||
294 | */ |
||
295 | public function getMethod() |
||
299 | |||
300 | /** |
||
301 | * Return an instance with the provided HTTP method. |
||
302 | * |
||
303 | * While HTTP method names are typically all uppercase characters, HTTP |
||
304 | * method names are case-sensitive and thus implementations SHOULD NOT |
||
305 | * modify the given string. |
||
306 | * |
||
307 | * This method MUST be implemented in such a way as to retain the |
||
308 | * immutability of the message, and MUST return an instance that has the |
||
309 | * changed request method. |
||
310 | * |
||
311 | * @param string $method Case-sensitive method. |
||
312 | * @return static |
||
313 | * @throws \InvalidArgumentException for invalid HTTP methods. |
||
314 | */ |
||
315 | public function withMethod($method) |
||
319 | |||
320 | /** |
||
321 | * Retrieves the URI instance. |
||
322 | * |
||
323 | * This method MUST return a UriInterface instance. |
||
324 | * |
||
325 | * @link http://tools.ietf.org/html/rfc3986#section-4.3 |
||
326 | * @return UriInterface Returns a UriInterface instance |
||
327 | * representing the URI of the request. |
||
328 | */ |
||
329 | public function getUri() |
||
333 | |||
334 | /** |
||
335 | * Returns an instance with the provided URI. |
||
336 | * |
||
337 | * This method MUST update the Host header of the returned request by |
||
338 | * default if the URI contains a host component. If the URI does not |
||
339 | * contain a host component, any pre-existing Host header MUST be carried |
||
340 | * over to the returned request. |
||
341 | * |
||
342 | * You can opt-in to preserving the original state of the Host header by |
||
343 | * setting `$preserveHost` to `true`. When `$preserveHost` is set to |
||
344 | * `true`, this method interacts with the Host header in the following ways: |
||
345 | * |
||
346 | * - If the Host header is missing or empty, and the new URI contains |
||
347 | * a host component, this method MUST update the Host header in the returned |
||
348 | * request. |
||
349 | * - If the Host header is missing or empty, and the new URI does not contain a |
||
350 | * host component, this method MUST NOT update the Host header in the returned |
||
351 | * request. |
||
352 | * - If a Host header is present and non-empty, this method MUST NOT update |
||
353 | * the Host header in the returned request. |
||
354 | * |
||
355 | * This method MUST be implemented in such a way as to retain the |
||
356 | * immutability of the message, and MUST return an instance that has the |
||
357 | * new UriInterface instance. |
||
358 | * |
||
359 | * @link http://tools.ietf.org/html/rfc3986#section-4.3 |
||
360 | * @param UriInterface $uri New request URI to use. |
||
361 | * @param bool $preserveHost Preserve the original state of the Host header. |
||
362 | * @return static |
||
363 | */ |
||
364 | public function withUri(UriInterface $uri, $preserveHost = false) |
||
368 | } |
||
369 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.