Skip to content

Commit 8d0a1c5

Browse files
committed
Merge pull request #11 from weierophinney/feature/update-from-psr
Updated to latest version of proposal
2 parents 05f67fe + ecdb955 commit 8d0a1c5

7 files changed

+349
-204
lines changed

src/IncomingRequestInterface.php

Lines changed: 91 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,76 @@
33
namespace Psr\Http\Message;
44

55
/**
6-
* An incoming (server-side) HTTP request.
6+
* Representation of an incoming, server-side HTTP request.
77
*
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.
1234
*/
13-
interface IncomingRequestInterface extends RequestInterface
35+
interface IncomingRequestInterface extends MessageInterface
1436
{
1537
/**
16-
* Retrieve cookies.
38+
* Retrieves the HTTP method of the request.
1739
*
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.
1946
*
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.
2355
*
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+
*
2460
* @return array
2561
*/
26-
public function getCookieParams();
62+
public function getServerParams();
2763

2864
/**
29-
* Set cookie parameters.
65+
* Retrieve cookies.
3066
*
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.
3668
*
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.
3872
*
39-
* @param array $cookies Cookie values
40-
* @return void
41-
* @throws \InvalidArgumentException For invalid cookie parameters.
73+
* @return array
4274
*/
43-
public function setCookieParams(array $cookies);
75+
public function getCookieParams();
4476

4577
/**
4678
* Retrieve query string arguments.
@@ -81,46 +113,59 @@ public function getFileParams();
81113
* PHP's $_POST superglobal. The data IS NOT REQUIRED to come from $_POST,
82114
* but MUST be an array.
83115
*
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-
*
87116
* @return array The deserialized body parameters, if any.
88117
*/
89118
public function getBodyParams();
90119

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-
104120
/**
105121
* Retrieve attributes derived from the request.
106122
*
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.
110128
*
111129
* @return array Attributes derived from the request.
112130
*/
113131
public function getAttributes();
114132

115133
/**
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.
117149
*
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().
121152
*
153+
* @see getAttributes()
122154
* @param array $attributes Attributes derived from the request.
123155
* @return void
124156
*/
125157
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);
126171
}

src/ResponseInterface.php renamed to src/IncomingResponseInterface.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
namespace Psr\Http\Message;
44

55
/**
6-
* An HTTP response message.
6+
* Representation of an incoming, client-side response.
7+
*
8+
* Per the HTTP specification, this interface includes accessors for
9+
* the following:
710
*
8-
* @link http://tools.ietf.org/html/rfc7231#section-6
9-
* @link http://tools.ietf.org/html/rfc7231#section-7
11+
* - Protocol version
12+
* - Status code and reason phrase
13+
* - Headers
14+
* - Message body
15+
*
16+
* As the response is the result of making a request, it is considered
17+
* immutable.
1018
*/
11-
interface ResponseInterface extends MessageInterface
19+
interface IncomingResponseInterface extends MessageInterface
1220
{
1321
/**
1422
* Gets the response Status-Code.
@@ -20,14 +28,6 @@ interface ResponseInterface extends MessageInterface
2028
*/
2129
public function getStatusCode();
2230

23-
/**
24-
* Sets the status code of this response.
25-
*
26-
* @param integer $code The 3-digit integer result code to set.
27-
* @throws \InvalidArgumentException For invalid status code arguments.
28-
*/
29-
public function setStatusCode($code);
30-
3131
/**
3232
* Gets the response Reason-Phrase, a short textual description of the Status-Code.
3333
*
@@ -42,16 +42,4 @@ public function setStatusCode($code);
4242
* @return string|null Reason phrase, or null if unknown.
4343
*/
4444
public function getReasonPhrase();
45-
46-
/**
47-
* Sets the Reason-Phrase of the response.
48-
*
49-
* If no Reason-Phrase is specified, implementations MAY choose to default
50-
* to the RFC 7231 or IANA recommended reason phrase for the response's
51-
* Status-Code.
52-
*
53-
* @param string $phrase The Reason-Phrase to set.
54-
* @throws \InvalidArgumentException For non-string $phrase arguments.
55-
*/
56-
public function setReasonPhrase($phrase);
5745
}

src/MessageInterface.php

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,13 @@ interface MessageInterface
2121
*/
2222
public function getProtocolVersion();
2323

24-
/**
25-
* Set the HTTP protocol version.
26-
*
27-
* The version string MUST contain only the HTTP version number (e.g.,
28-
* "1.1", "1.0").
29-
*
30-
* @param string $version HTTP protocol version
31-
* @return void
32-
*/
33-
public function setProtocolVersion($version);
34-
3524
/**
3625
* Gets the body of the message.
3726
*
3827
* @return StreamableInterface|null Returns the body, or null if not set.
3928
*/
4029
public function getBody();
4130

42-
/**
43-
* Sets the body of the message.
44-
*
45-
* The body MUST be a StreamableInterface object. Setting the body to null MUST
46-
* remove the existing body.
47-
*
48-
* @param StreamableInterface|null $body Body.
49-
* @return void
50-
* @throws \InvalidArgumentException When the body is not valid.
51-
*/
52-
public function setBody(StreamableInterface $body = null);
53-
5431
/**
5532
* Gets all message headers.
5633
*
@@ -85,12 +62,15 @@ public function getHeaders();
8562
public function hasHeader($header);
8663

8764
/**
88-
* Retrieve a header by the given case-insensitive name as a string.
65+
* Retrieve a header by the given case-insensitive name, as a string.
8966
*
9067
* This method returns all of the header values of the given
9168
* case-insensitive header name as a string concatenated together using
9269
* a comma.
9370
*
71+
* NOTE: Not all header values may be appropriately represented using
72+
* comma concatenation.
73+
*
9474
* @param string $header Case-insensitive header name.
9575
* @return string
9676
*/
@@ -103,39 +83,4 @@ public function getHeader($header);
10383
* @return string[]
10484
*/
10585
public function getHeaderAsArray($header);
106-
107-
/**
108-
* Sets a header, replacing any existing values of any headers with the
109-
* same case-insensitive name.
110-
*
111-
* The header name is case-insensitive. The header values MUST be a string
112-
* or an array of strings.
113-
*
114-
* @param string $header Header name
115-
* @param string|string[] $value Header value(s).
116-
* @return void
117-
* @throws \InvalidArgumentException for invalid header names or values.
118-
*/
119-
public function setHeader($header, $value);
120-
121-
/**
122-
* Appends a header value for the specified header.
123-
*
124-
* Existing values for the specified header will be maintained. The new
125-
* value(s) will be appended to the existing list.
126-
*
127-
* @param string $header Header name to add
128-
* @param string|string[] $value Header value(s).
129-
* @return void
130-
* @throws \InvalidArgumentException for invalid header names or values.
131-
*/
132-
public function addHeader($header, $value);
133-
134-
/**
135-
* Remove a specific header by case-insensitive name.
136-
*
137-
* @param string $header HTTP header to remove
138-
* @return void
139-
*/
140-
public function removeHeader($header);
14186
}

0 commit comments

Comments
 (0)