5
5
/**
6
6
* Representation of an incoming, server-side HTTP request.
7
7
*
8
- * Per the HTTP specification, this interface includes accessors for
9
- * the following:
8
+ * Per the HTTP specification, this interface includes properties for
9
+ * each of the following:
10
10
*
11
11
* - Protocol version
12
12
* - HTTP method
24
24
* - Deserialized body parameters (generally from $_POST)
25
25
*
26
26
* $_SERVER and $_FILES values MUST be treated as immutable, as they represent
27
- * application state at the time of request. The other values SHOULD be
28
- * mutable, as they can be restored from $_SERVER, $_FILES, or the request
29
- * body, and may need treatment during the application (e.g., body parameters
30
- * may be deserialized based on content type).
27
+ * application state at the time of request; as such, no methods are provided
28
+ * to allow modification of those values. The other values provide such methods,
29
+ * as they can be restored from $_SERVER, $_FILES, or the request body, and may
30
+ * need treatment during the application (e.g., body parameters may be
31
+ * deserialized based on content type).
31
32
*
32
33
* Additionally, this interface recognizes the utility of introspecting a
33
34
* request to derive and match additional parameters (e.g., via URI path
34
35
* matching, decrypting cookie values, deserializing non-form-encoded body
35
36
* content, matching authorization headers to users, etc). These parameters
36
- * are stored in an "attributes" property, which MUST be mutable.
37
+ * are stored in an "attributes" property.
38
+ *
39
+ * Requests are considered immutable; all methods that might change state MUST
40
+ * be implemented such that they retain the internal state of the current
41
+ * message and return a new instance that contains the changed state.
37
42
*/
38
43
interface ServerRequestInterface extends RequestInterface
39
44
{
@@ -69,8 +74,12 @@ public function getCookieParams();
69
74
* be compatible with the structure of $_COOKIE. Typically, this data will
70
75
* be injected at instantiation.
71
76
*
77
+ * This method MUST be implemented in such a way as to retain the
78
+ * immutability of the message, and MUST return a new instance that has the
79
+ * updated cookie values.
80
+ *
72
81
* @param array $cookies Array of key/value pairs representing cookies.
73
- * @return void
82
+ * @return ServerRequestInterface
74
83
*/
75
84
public function setCookieParams (array $ cookies );
76
85
@@ -102,9 +111,13 @@ public function getQueryParams();
102
111
* Setting query string arguments MUST NOT change the URL stored by the
103
112
* request, nor the values in the server params.
104
113
*
114
+ * This method MUST be implemented in such a way as to retain the
115
+ * immutability of the message, and MUST return a new instance that has the
116
+ * updated query string arguments.
117
+ *
105
118
* @param array $query Array of query string arguments, typically from
106
119
* $_GET.
107
- * @return void
120
+ * @return ServerRequestInterface
108
121
*/
109
122
public function setQueryParams (array $ query );
110
123
@@ -143,8 +156,12 @@ public function getBodyParams();
143
156
* a JSON payload, this method could be used to inject the deserialized
144
157
* parameters.
145
158
*
159
+ * This method MUST be implemented in such a way as to retain the
160
+ * immutability of the message, and MUST return a new instance that has the
161
+ * updated body parameters.
162
+ *
146
163
* @param array $params The deserialized body parameters.
147
- * @return void
164
+ * @return ServerRequestInterface
148
165
*/
149
166
public function setBodyParams (array $ params );
150
167
@@ -181,9 +198,13 @@ public function getAttribute($attribute, $default = null);
181
198
* This method allows setting request attributes, as described in
182
199
* getAttributes().
183
200
*
201
+ * This method MUST be implemented in such a way as to retain the
202
+ * immutability of the message, and MUST return a new instance that has the
203
+ * updated attributes.
204
+ *
184
205
* @see getAttributes()
185
206
* @param array $attributes Attributes derived from the request.
186
- * @return void
207
+ * @return ServerRequestInterface
187
208
*/
188
209
public function setAttributes (array $ attributes );
189
210
@@ -193,10 +214,14 @@ public function setAttributes(array $attributes);
193
214
* This method allows setting a single derived request attribute as
194
215
* described in getAttributes().
195
216
*
217
+ * This method MUST be implemented in such a way as to retain the
218
+ * immutability of the message, and MUST return a new instance that has the
219
+ * updated attribute.
220
+ *
196
221
* @see getAttributes()
197
222
* @param string $attribute The attribute name.
198
223
* @param mixed $value The value of the attribute.
199
- * @return void
224
+ * @return ServerRequestInterface
200
225
*/
201
226
public function setAttribute ($ attribute , $ value );
202
227
}
0 commit comments