|
3 | 3 | namespace Psr\Http\Message;
|
4 | 4 |
|
5 | 5 | /**
|
6 |
| - * An incoming (server-side) HTTP request. |
| 6 | + * Representation of an incoming, server-side HTTP request. |
7 | 7 | *
|
8 |
| - * This interface further describes a server-side request and provides |
9 |
| - * accessors and mutators around common request data, including query |
10 |
| - * string arguments, body parameters, upload file metadata, cookies, and |
11 |
| - * arbitrary attributes derived from the request by the application. |
| 8 | + * Per the HTTP specification, this interface includes accessors for |
| 9 | + * the following: |
| 10 | + * |
| 11 | + * - Protocol version |
| 12 | + * - HTTP method |
| 13 | + * - URL |
| 14 | + * - Headers |
| 15 | + * - Message body |
| 16 | + * |
| 17 | + * Additionally, it encapsulates all data as it has arrived to the |
| 18 | + * application from the PHP environment, including: |
| 19 | + * |
| 20 | + * - The values represented in $_SERVER. |
| 21 | + * - Any cookies provided (generally via $_COOKIE) |
| 22 | + * - Query string arguments (generally via $_GET, or as parsed via parse_str()) |
| 23 | + * - Upload files, if any (as represented by $_FILES) |
| 24 | + * - Deserialized body parameters (generally from $_POST) |
| 25 | + * |
| 26 | + * The above values MUST be immutable, in order to ensure that all consumers of |
| 27 | + * the request instance within a given request cycle receive the same information. |
| 28 | + * |
| 29 | + * Additionally, this interface recognizes the utility of introspecting a |
| 30 | + * request to derive and match additional parameters (e.g., via URI path |
| 31 | + * matching, decrypting cookie values, deserializing non-form-encoded body |
| 32 | + * content, matching authorization headers to users, etc). These parameters |
| 33 | + * are stored in an "attributes" property, which MUST be mutable. |
12 | 34 | */
|
13 |
| -interface IncomingRequestInterface extends RequestInterface |
| 35 | +interface IncomingRequestInterface extends MessageInterface |
14 | 36 | {
|
15 | 37 | /**
|
16 |
| - * Retrieve cookies. |
| 38 | + * Retrieves the HTTP method of the request. |
17 | 39 | *
|
18 |
| - * Retrieves cookies sent by the client to the server. |
| 40 | + * @return string Returns the request method. |
| 41 | + */ |
| 42 | + public function getMethod(); |
| 43 | + |
| 44 | + /** |
| 45 | + * Retrieves the request URL. |
19 | 46 | *
|
20 |
| - * The assumption is these are injected during instantiation, typically |
21 |
| - * from PHP's $_COOKIE superglobal. The data IS NOT REQUIRED to come from |
22 |
| - * $_COOKIE, but MUST be compatible with the structure of $_COOKIE. |
| 47 | + * @link http://tools.ietf.org/html/rfc3986#section-4.3 |
| 48 | + * @return string Returns the URL as a string. The URL SHOULD be an absolute |
| 49 | + * URI as specified in RFC 3986, but MAY be a relative URI. |
| 50 | + */ |
| 51 | + public function getUrl(); |
| 52 | + |
| 53 | + /** |
| 54 | + * Retrieve server parameters. |
23 | 55 | *
|
| 56 | + * Retrieves data related to the incoming request environment, |
| 57 | + * typically derived from PHP's $_SERVER superglobal. The data IS NOT |
| 58 | + * REQUIRED to originate from $_SERVER. |
| 59 | + * |
24 | 60 | * @return array
|
25 | 61 | */
|
26 |
| - public function getCookieParams(); |
| 62 | + public function getServerParams(); |
27 | 63 |
|
28 | 64 | /**
|
29 |
| - * Set cookie parameters. |
| 65 | + * Retrieve cookies. |
30 | 66 | *
|
31 |
| - * Allows a library to set the cookie parameters. Use cases include |
32 |
| - * libraries that implement additional security practices, such as |
33 |
| - * encrypting or hashing cookie values; in such cases, they will read |
34 |
| - * the original value, filter them, and re-inject into the incoming |
35 |
| - * request. |
| 67 | + * Retrieves cookies sent by the client to the server. |
36 | 68 | *
|
37 |
| - * The value provided MUST be compatible with the structure of $_COOKIE. |
| 69 | + * The assumption is these are injected during instantiation, typically |
| 70 | + * from PHP's $_COOKIE superglobal. The data IS NOT REQUIRED to come from |
| 71 | + * $_COOKIE, but MUST be compatible with the structure of $_COOKIE. |
38 | 72 | *
|
39 |
| - * @param array $cookies Cookie values |
40 |
| - * @return void |
41 |
| - * @throws \InvalidArgumentException For invalid cookie parameters. |
| 73 | + * @return array |
42 | 74 | */
|
43 |
| - public function setCookieParams(array $cookies); |
| 75 | + public function getCookieParams(); |
44 | 76 |
|
45 | 77 | /**
|
46 | 78 | * Retrieve query string arguments.
|
@@ -81,46 +113,59 @@ public function getFileParams();
|
81 | 113 | * PHP's $_POST superglobal. The data IS NOT REQUIRED to come from $_POST,
|
82 | 114 | * but MUST be an array.
|
83 | 115 | *
|
84 |
| - * In cases where the request content cannot be coerced to an array, the |
85 |
| - * parent getBody() method should be used to retrieve the body content. |
86 |
| - * |
87 | 116 | * @return array The deserialized body parameters, if any.
|
88 | 117 | */
|
89 | 118 | public function getBodyParams();
|
90 | 119 |
|
91 |
| - /** |
92 |
| - * Set the request body parameters. |
93 |
| - * |
94 |
| - * If the body content can be deserialized to an array, the values obtained |
95 |
| - * MAY then be injected into the response using this method. This method |
96 |
| - * will typically be invoked by a factory marshaling request parameters. |
97 |
| - * |
98 |
| - * @param array $values The deserialized body parameters, if any. |
99 |
| - * @return void |
100 |
| - * @throws \InvalidArgumentException For $values that cannot be accepted. |
101 |
| - */ |
102 |
| - public function setBodyParams(array $values); |
103 |
| - |
104 | 120 | /**
|
105 | 121 | * Retrieve attributes derived from the request.
|
106 | 122 | *
|
107 |
| - * If a router or similar is used to match against the path and/or request, |
108 |
| - * this method MAY be used to retrieve the results, so long as those |
109 |
| - * results can be represented as an array. |
| 123 | + * The request "attributes" may be used to allow injection of any |
| 124 | + * parameters derived from the request: e.g., the results of path |
| 125 | + * match operations; the results of decrypting cookies; the results of |
| 126 | + * deserializing non-form-encoded message bodies; etc. Attributes |
| 127 | + * will be application and request specific, and CAN be mutable. |
110 | 128 | *
|
111 | 129 | * @return array Attributes derived from the request.
|
112 | 130 | */
|
113 | 131 | public function getAttributes();
|
114 | 132 |
|
115 | 133 | /**
|
116 |
| - * Set attributes derived from the request |
| 134 | + * Retrieve a single derived request attribute. |
| 135 | + * |
| 136 | + * Retrieves a single derived request attribute as described in |
| 137 | + * getAttributes(). If the attribute has not been previously set, returns |
| 138 | + * the default value as provided. |
| 139 | + * |
| 140 | + * @see getAttributes() |
| 141 | + * @param string $attribute Attribute name. |
| 142 | + * @param mixed $default Default value to return if the attribute does not exist. |
| 143 | + * @return mixed |
| 144 | + */ |
| 145 | + public function getAttribute($attribute, $default = null); |
| 146 | + |
| 147 | + /** |
| 148 | + * Set attributes derived from the request. |
117 | 149 | *
|
118 |
| - * If a router or similar is used to match against the path and/or request, |
119 |
| - * this method MAY be used to inject the request with the results, so long |
120 |
| - * as those results can be represented as an array. |
| 150 | + * This method allows setting request attributes, as described in |
| 151 | + * getAttributes(). |
121 | 152 | *
|
| 153 | + * @see getAttributes() |
122 | 154 | * @param array $attributes Attributes derived from the request.
|
123 | 155 | * @return void
|
124 | 156 | */
|
125 | 157 | public function setAttributes(array $attributes);
|
| 158 | + |
| 159 | + /** |
| 160 | + * Set a single derived request attribute. |
| 161 | + * |
| 162 | + * This method allows setting a single derived request attribute as |
| 163 | + * described in getAttributes(). |
| 164 | + * |
| 165 | + * @see getAttributes() |
| 166 | + * @param string $attribute The attribute name. |
| 167 | + * @param mixed $value The value of the attribute. |
| 168 | + * @return void |
| 169 | + */ |
| 170 | + public function setAttribute($attribute, $value); |
126 | 171 | }
|
0 commit comments