Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Psr\Http\Message;
|
Chris@0
|
4
|
Chris@0
|
5 /**
|
Chris@0
|
6 * Representation of an incoming, server-side HTTP request.
|
Chris@0
|
7 *
|
Chris@0
|
8 * Per the HTTP specification, this interface includes properties for
|
Chris@0
|
9 * each of the following:
|
Chris@0
|
10 *
|
Chris@0
|
11 * - Protocol version
|
Chris@0
|
12 * - HTTP method
|
Chris@0
|
13 * - URI
|
Chris@0
|
14 * - Headers
|
Chris@0
|
15 * - Message body
|
Chris@0
|
16 *
|
Chris@0
|
17 * Additionally, it encapsulates all data as it has arrived to the
|
Chris@0
|
18 * application from the CGI and/or PHP environment, including:
|
Chris@0
|
19 *
|
Chris@0
|
20 * - The values represented in $_SERVER.
|
Chris@0
|
21 * - Any cookies provided (generally via $_COOKIE)
|
Chris@0
|
22 * - Query string arguments (generally via $_GET, or as parsed via parse_str())
|
Chris@0
|
23 * - Upload files, if any (as represented by $_FILES)
|
Chris@0
|
24 * - Deserialized body parameters (generally from $_POST)
|
Chris@0
|
25 *
|
Chris@0
|
26 * $_SERVER values MUST be treated as immutable, as they represent application
|
Chris@0
|
27 * state at the time of request; as such, no methods are provided to allow
|
Chris@0
|
28 * modification of those values. The other values provide such methods, as they
|
Chris@0
|
29 * can be restored from $_SERVER or the request body, and may need treatment
|
Chris@0
|
30 * during the application (e.g., body parameters may be deserialized based on
|
Chris@0
|
31 * content type).
|
Chris@0
|
32 *
|
Chris@0
|
33 * Additionally, this interface recognizes the utility of introspecting a
|
Chris@0
|
34 * request to derive and match additional parameters (e.g., via URI path
|
Chris@0
|
35 * matching, decrypting cookie values, deserializing non-form-encoded body
|
Chris@0
|
36 * content, matching authorization headers to users, etc). These parameters
|
Chris@0
|
37 * are stored in an "attributes" property.
|
Chris@0
|
38 *
|
Chris@0
|
39 * Requests are considered immutable; all methods that might change state MUST
|
Chris@0
|
40 * be implemented such that they retain the internal state of the current
|
Chris@0
|
41 * message and return an instance that contains the changed state.
|
Chris@0
|
42 */
|
Chris@0
|
43 interface ServerRequestInterface extends RequestInterface
|
Chris@0
|
44 {
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Retrieve server parameters.
|
Chris@0
|
47 *
|
Chris@0
|
48 * Retrieves data related to the incoming request environment,
|
Chris@0
|
49 * typically derived from PHP's $_SERVER superglobal. The data IS NOT
|
Chris@0
|
50 * REQUIRED to originate from $_SERVER.
|
Chris@0
|
51 *
|
Chris@0
|
52 * @return array
|
Chris@0
|
53 */
|
Chris@0
|
54 public function getServerParams();
|
Chris@0
|
55
|
Chris@0
|
56 /**
|
Chris@0
|
57 * Retrieve cookies.
|
Chris@0
|
58 *
|
Chris@0
|
59 * Retrieves cookies sent by the client to the server.
|
Chris@0
|
60 *
|
Chris@0
|
61 * The data MUST be compatible with the structure of the $_COOKIE
|
Chris@0
|
62 * superglobal.
|
Chris@0
|
63 *
|
Chris@0
|
64 * @return array
|
Chris@0
|
65 */
|
Chris@0
|
66 public function getCookieParams();
|
Chris@0
|
67
|
Chris@0
|
68 /**
|
Chris@0
|
69 * Return an instance with the specified cookies.
|
Chris@0
|
70 *
|
Chris@0
|
71 * The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST
|
Chris@0
|
72 * be compatible with the structure of $_COOKIE. Typically, this data will
|
Chris@0
|
73 * be injected at instantiation.
|
Chris@0
|
74 *
|
Chris@0
|
75 * This method MUST NOT update the related Cookie header of the request
|
Chris@0
|
76 * instance, nor related values in the server params.
|
Chris@0
|
77 *
|
Chris@0
|
78 * This method MUST be implemented in such a way as to retain the
|
Chris@0
|
79 * immutability of the message, and MUST return an instance that has the
|
Chris@0
|
80 * updated cookie values.
|
Chris@0
|
81 *
|
Chris@0
|
82 * @param array $cookies Array of key/value pairs representing cookies.
|
Chris@0
|
83 * @return static
|
Chris@0
|
84 */
|
Chris@0
|
85 public function withCookieParams(array $cookies);
|
Chris@0
|
86
|
Chris@0
|
87 /**
|
Chris@0
|
88 * Retrieve query string arguments.
|
Chris@0
|
89 *
|
Chris@0
|
90 * Retrieves the deserialized query string arguments, if any.
|
Chris@0
|
91 *
|
Chris@0
|
92 * Note: the query params might not be in sync with the URI or server
|
Chris@0
|
93 * params. If you need to ensure you are only getting the original
|
Chris@0
|
94 * values, you may need to parse the query string from `getUri()->getQuery()`
|
Chris@0
|
95 * or from the `QUERY_STRING` server param.
|
Chris@0
|
96 *
|
Chris@0
|
97 * @return array
|
Chris@0
|
98 */
|
Chris@0
|
99 public function getQueryParams();
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * Return an instance with the specified query string arguments.
|
Chris@0
|
103 *
|
Chris@0
|
104 * These values SHOULD remain immutable over the course of the incoming
|
Chris@0
|
105 * request. They MAY be injected during instantiation, such as from PHP's
|
Chris@0
|
106 * $_GET superglobal, or MAY be derived from some other value such as the
|
Chris@0
|
107 * URI. In cases where the arguments are parsed from the URI, the data
|
Chris@0
|
108 * MUST be compatible with what PHP's parse_str() would return for
|
Chris@0
|
109 * purposes of how duplicate query parameters are handled, and how nested
|
Chris@0
|
110 * sets are handled.
|
Chris@0
|
111 *
|
Chris@0
|
112 * Setting query string arguments MUST NOT change the URI stored by the
|
Chris@0
|
113 * request, nor the values in the server params.
|
Chris@0
|
114 *
|
Chris@0
|
115 * This method MUST be implemented in such a way as to retain the
|
Chris@0
|
116 * immutability of the message, and MUST return an instance that has the
|
Chris@0
|
117 * updated query string arguments.
|
Chris@0
|
118 *
|
Chris@0
|
119 * @param array $query Array of query string arguments, typically from
|
Chris@0
|
120 * $_GET.
|
Chris@0
|
121 * @return static
|
Chris@0
|
122 */
|
Chris@0
|
123 public function withQueryParams(array $query);
|
Chris@0
|
124
|
Chris@0
|
125 /**
|
Chris@0
|
126 * Retrieve normalized file upload data.
|
Chris@0
|
127 *
|
Chris@0
|
128 * This method returns upload metadata in a normalized tree, with each leaf
|
Chris@0
|
129 * an instance of Psr\Http\Message\UploadedFileInterface.
|
Chris@0
|
130 *
|
Chris@0
|
131 * These values MAY be prepared from $_FILES or the message body during
|
Chris@0
|
132 * instantiation, or MAY be injected via withUploadedFiles().
|
Chris@0
|
133 *
|
Chris@0
|
134 * @return array An array tree of UploadedFileInterface instances; an empty
|
Chris@0
|
135 * array MUST be returned if no data is present.
|
Chris@0
|
136 */
|
Chris@0
|
137 public function getUploadedFiles();
|
Chris@0
|
138
|
Chris@0
|
139 /**
|
Chris@0
|
140 * Create a new instance with the specified uploaded files.
|
Chris@0
|
141 *
|
Chris@0
|
142 * This method MUST be implemented in such a way as to retain the
|
Chris@0
|
143 * immutability of the message, and MUST return an instance that has the
|
Chris@0
|
144 * updated body parameters.
|
Chris@0
|
145 *
|
Chris@0
|
146 * @param array $uploadedFiles An array tree of UploadedFileInterface instances.
|
Chris@0
|
147 * @return static
|
Chris@0
|
148 * @throws \InvalidArgumentException if an invalid structure is provided.
|
Chris@0
|
149 */
|
Chris@0
|
150 public function withUploadedFiles(array $uploadedFiles);
|
Chris@0
|
151
|
Chris@0
|
152 /**
|
Chris@0
|
153 * Retrieve any parameters provided in the request body.
|
Chris@0
|
154 *
|
Chris@0
|
155 * If the request Content-Type is either application/x-www-form-urlencoded
|
Chris@0
|
156 * or multipart/form-data, and the request method is POST, this method MUST
|
Chris@0
|
157 * return the contents of $_POST.
|
Chris@0
|
158 *
|
Chris@0
|
159 * Otherwise, this method may return any results of deserializing
|
Chris@0
|
160 * the request body content; as parsing returns structured content, the
|
Chris@0
|
161 * potential types MUST be arrays or objects only. A null value indicates
|
Chris@0
|
162 * the absence of body content.
|
Chris@0
|
163 *
|
Chris@0
|
164 * @return null|array|object The deserialized body parameters, if any.
|
Chris@0
|
165 * These will typically be an array or object.
|
Chris@0
|
166 */
|
Chris@0
|
167 public function getParsedBody();
|
Chris@0
|
168
|
Chris@0
|
169 /**
|
Chris@0
|
170 * Return an instance with the specified body parameters.
|
Chris@0
|
171 *
|
Chris@0
|
172 * These MAY be injected during instantiation.
|
Chris@0
|
173 *
|
Chris@0
|
174 * If the request Content-Type is either application/x-www-form-urlencoded
|
Chris@0
|
175 * or multipart/form-data, and the request method is POST, use this method
|
Chris@0
|
176 * ONLY to inject the contents of $_POST.
|
Chris@0
|
177 *
|
Chris@0
|
178 * The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
|
Chris@0
|
179 * deserializing the request body content. Deserialization/parsing returns
|
Chris@0
|
180 * structured data, and, as such, this method ONLY accepts arrays or objects,
|
Chris@0
|
181 * or a null value if nothing was available to parse.
|
Chris@0
|
182 *
|
Chris@0
|
183 * As an example, if content negotiation determines that the request data
|
Chris@0
|
184 * is a JSON payload, this method could be used to create a request
|
Chris@0
|
185 * instance with the deserialized parameters.
|
Chris@0
|
186 *
|
Chris@0
|
187 * This method MUST be implemented in such a way as to retain the
|
Chris@0
|
188 * immutability of the message, and MUST return an instance that has the
|
Chris@0
|
189 * updated body parameters.
|
Chris@0
|
190 *
|
Chris@0
|
191 * @param null|array|object $data The deserialized body data. This will
|
Chris@0
|
192 * typically be in an array or object.
|
Chris@0
|
193 * @return static
|
Chris@0
|
194 * @throws \InvalidArgumentException if an unsupported argument type is
|
Chris@0
|
195 * provided.
|
Chris@0
|
196 */
|
Chris@0
|
197 public function withParsedBody($data);
|
Chris@0
|
198
|
Chris@0
|
199 /**
|
Chris@0
|
200 * Retrieve attributes derived from the request.
|
Chris@0
|
201 *
|
Chris@0
|
202 * The request "attributes" may be used to allow injection of any
|
Chris@0
|
203 * parameters derived from the request: e.g., the results of path
|
Chris@0
|
204 * match operations; the results of decrypting cookies; the results of
|
Chris@0
|
205 * deserializing non-form-encoded message bodies; etc. Attributes
|
Chris@0
|
206 * will be application and request specific, and CAN be mutable.
|
Chris@0
|
207 *
|
Chris@0
|
208 * @return array Attributes derived from the request.
|
Chris@0
|
209 */
|
Chris@0
|
210 public function getAttributes();
|
Chris@0
|
211
|
Chris@0
|
212 /**
|
Chris@0
|
213 * Retrieve a single derived request attribute.
|
Chris@0
|
214 *
|
Chris@0
|
215 * Retrieves a single derived request attribute as described in
|
Chris@0
|
216 * getAttributes(). If the attribute has not been previously set, returns
|
Chris@0
|
217 * the default value as provided.
|
Chris@0
|
218 *
|
Chris@0
|
219 * This method obviates the need for a hasAttribute() method, as it allows
|
Chris@0
|
220 * specifying a default value to return if the attribute is not found.
|
Chris@0
|
221 *
|
Chris@0
|
222 * @see getAttributes()
|
Chris@0
|
223 * @param string $name The attribute name.
|
Chris@0
|
224 * @param mixed $default Default value to return if the attribute does not exist.
|
Chris@0
|
225 * @return mixed
|
Chris@0
|
226 */
|
Chris@0
|
227 public function getAttribute($name, $default = null);
|
Chris@0
|
228
|
Chris@0
|
229 /**
|
Chris@0
|
230 * Return an instance with the specified derived request attribute.
|
Chris@0
|
231 *
|
Chris@0
|
232 * This method allows setting a single derived request attribute as
|
Chris@0
|
233 * described in getAttributes().
|
Chris@0
|
234 *
|
Chris@0
|
235 * This method MUST be implemented in such a way as to retain the
|
Chris@0
|
236 * immutability of the message, and MUST return an instance that has the
|
Chris@0
|
237 * updated attribute.
|
Chris@0
|
238 *
|
Chris@0
|
239 * @see getAttributes()
|
Chris@0
|
240 * @param string $name The attribute name.
|
Chris@0
|
241 * @param mixed $value The value of the attribute.
|
Chris@0
|
242 * @return static
|
Chris@0
|
243 */
|
Chris@0
|
244 public function withAttribute($name, $value);
|
Chris@0
|
245
|
Chris@0
|
246 /**
|
Chris@0
|
247 * Return an instance that removes the specified derived request attribute.
|
Chris@0
|
248 *
|
Chris@0
|
249 * This method allows removing a single derived request attribute as
|
Chris@0
|
250 * described in getAttributes().
|
Chris@0
|
251 *
|
Chris@0
|
252 * This method MUST be implemented in such a way as to retain the
|
Chris@0
|
253 * immutability of the message, and MUST return an instance that removes
|
Chris@0
|
254 * the attribute.
|
Chris@0
|
255 *
|
Chris@0
|
256 * @see getAttributes()
|
Chris@0
|
257 * @param string $name The attribute name.
|
Chris@0
|
258 * @return static
|
Chris@0
|
259 */
|
Chris@0
|
260 public function withoutAttribute($name);
|
Chris@0
|
261 }
|