55/**
66 * Representation of an incoming, server-side HTTP request.
77 *
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:
1010 *
1111 * - Protocol version
1212 * - HTTP method
2424 * - Deserialized body parameters (generally from $_POST)
2525 *
2626 * $_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).
3132 *
3233 * Additionally, this interface recognizes the utility of introspecting a
3334 * request to derive and match additional parameters (e.g., via URI path
3435 * matching, decrypting cookie values, deserializing non-form-encoded body
3536 * 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.
3742 */
3843interface ServerRequestInterface extends RequestInterface
3944{
@@ -69,8 +74,12 @@ public function getCookieParams();
6974 * be compatible with the structure of $_COOKIE. Typically, this data will
7075 * be injected at instantiation.
7176 *
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+ *
7281 * @param array $cookies Array of key/value pairs representing cookies.
73- * @return void
82+ * @return ServerRequestInterface
7483 */
7584 public function setCookieParams (array $ cookies );
7685
@@ -102,9 +111,13 @@ public function getQueryParams();
102111 * Setting query string arguments MUST NOT change the URL stored by the
103112 * request, nor the values in the server params.
104113 *
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+ *
105118 * @param array $query Array of query string arguments, typically from
106119 * $_GET.
107- * @return void
120+ * @return ServerRequestInterface
108121 */
109122 public function setQueryParams (array $ query );
110123
@@ -143,8 +156,12 @@ public function getBodyParams();
143156 * a JSON payload, this method could be used to inject the deserialized
144157 * parameters.
145158 *
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+ *
146163 * @param array $params The deserialized body parameters.
147- * @return void
164+ * @return ServerRequestInterface
148165 */
149166 public function setBodyParams (array $ params );
150167
@@ -181,9 +198,13 @@ public function getAttribute($attribute, $default = null);
181198 * This method allows setting request attributes, as described in
182199 * getAttributes().
183200 *
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+ *
184205 * @see getAttributes()
185206 * @param array $attributes Attributes derived from the request.
186- * @return void
207+ * @return ServerRequestInterface
187208 */
188209 public function setAttributes (array $ attributes );
189210
@@ -193,10 +214,14 @@ public function setAttributes(array $attributes);
193214 * This method allows setting a single derived request attribute as
194215 * described in getAttributes().
195216 *
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+ *
196221 * @see getAttributes()
197222 * @param string $attribute The attribute name.
198223 * @param mixed $value The value of the attribute.
199- * @return void
224+ * @return ServerRequestInterface
200225 */
201226 public function setAttribute ($ attribute , $ value );
202227}
0 commit comments