Skip to content

Commit 05f67fe

Browse files
committed
Merge pull request #6 from weierophinney/hotfix/update-to-latest
Updated to php-fig/fig-standards@476606bb
2 parents 80c8d95 + a5f5432 commit 05f67fe

File tree

5 files changed

+102
-133
lines changed

5 files changed

+102
-133
lines changed

src/IncomingRequestInterface.php

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* An incoming (server-side) HTTP request.
77
*
88
* This interface further describes a server-side request and provides
9-
* accessors and mutators around common request data, such as query
9+
* accessors and mutators around common request data, including query
1010
* string arguments, body parameters, upload file metadata, cookies, and
11-
* matched routing parameters.
11+
* arbitrary attributes derived from the request by the application.
1212
*/
1313
interface IncomingRequestInterface extends RequestInterface
1414
{
@@ -18,13 +18,10 @@ interface IncomingRequestInterface extends RequestInterface
1818
* Retrieves cookies sent by the client to the server.
1919
*
2020
* The assumption is these are injected during instantiation, typically
21-
* from PHP's $_COOKIE superglobal, and should remain immutable over the
22-
* course of the incoming request.
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.
2323
*
24-
* The return value can be either an array or an object that acts like
25-
* an array (e.g., implements ArrayAccess, or an ArrayObject).
26-
*
27-
* @return array|\ArrayAccess
24+
* @return array
2825
*/
2926
public function getCookieParams();
3027

@@ -35,28 +32,28 @@ public function getCookieParams();
3532
* libraries that implement additional security practices, such as
3633
* encrypting or hashing cookie values; in such cases, they will read
3734
* the original value, filter them, and re-inject into the incoming
38-
* request..
39-
*
40-
* The value provided should be an array or array-like object
41-
* (e.g., implements ArrayAccess, or an ArrayObject).
35+
* request.
4236
*
43-
* @param array|\ArrayAccess $cookies Cookie values/structs
37+
* The value provided MUST be compatible with the structure of $_COOKIE.
4438
*
39+
* @param array $cookies Cookie values
4540
* @return void
41+
* @throws \InvalidArgumentException For invalid cookie parameters.
4642
*/
47-
public function setCookieParams($cookies);
43+
public function setCookieParams(array $cookies);
4844

4945
/**
5046
* Retrieve query string arguments.
5147
*
5248
* Retrieves the deserialized query string arguments, if any.
5349
*
54-
* The assumption is these are injected during instantiation, typically
55-
* from PHP's $_GET superglobal, and should remain immutable over the
56-
* course of the incoming request.
57-
*
58-
* The return value can be either an array or an object that acts like
59-
* an array (e.g., implements ArrayAccess, or an ArrayObject).
50+
* These values SHOULD remain immutable over the course of the incoming
51+
* request. They MAY be injected during instantiation, such as from PHP's
52+
* $_GET superglobal, or MAY be derived from some other value such as the
53+
* URI. In cases where the arguments are parsed from the URI, the data
54+
* MUST be compatible with what PHP's `parse_str()` would return for
55+
* purposes of how duplicate query parameters are handled, and how nested
56+
* sets are handled.
6057
*
6158
* @return array
6259
*/
@@ -65,15 +62,12 @@ public function getQueryParams();
6562
/**
6663
* Retrieve the upload file metadata.
6764
*
68-
* This method should return file upload metadata in the same structure
65+
* This method MUST return file upload metadata in the same structure
6966
* as PHP's $_FILES superglobal.
7067
*
71-
* The assumption is these are injected during instantiation, typically
72-
* from PHP's $_FILES superglobal, and should remain immutable over the
73-
* course of the incoming request.
74-
*
75-
* The return value can be either an array or an object that acts like
76-
* an array (e.g., implements ArrayAccess, or an ArrayObject).
68+
* These values SHOULD remain immutable over the course of the incoming
69+
* request. They MAY be injected during instantiation, such as from PHP's
70+
* $_FILES superglobal, or MAY be derived from other sources.
7771
*
7872
* @return array Upload file(s) metadata, if any.
7973
*/
@@ -82,56 +76,51 @@ public function getFileParams();
8276
/**
8377
* Retrieve any parameters provided in the request body.
8478
*
85-
* If the request body can be deserialized, and if the deserialized values
86-
* can be represented as an array or object, this method can be used to
87-
* retrieve them.
79+
* If the request body can be deserialized to an array, this method MAY be
80+
* used to retrieve them. These MAY be injected during instantiation from
81+
* PHP's $_POST superglobal. The data IS NOT REQUIRED to come from $_POST,
82+
* but MUST be an array.
8883
*
89-
* In other cases, the parent getBody() method should be used to retrieve
90-
* the body content.
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.
9186
*
92-
* @return array|object The deserialized body parameters, if any. These may
93-
* be either an array or an object, though an array or
94-
* array-like object is recommended.
87+
* @return array The deserialized body parameters, if any.
9588
*/
9689
public function getBodyParams();
9790

9891
/**
9992
* Set the request body parameters.
10093
*
101-
* If the body content can be deserialized, the values obtained may then
102-
* be injected into the response using this method. This method will
103-
* typically be invoked by a factory marshaling request parameters.
104-
*
105-
* @param array|object $values The deserialized body parameters, if any.
106-
* These may be either an array or an object,
107-
* though an array or array-like object is
108-
* recommended.
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.
10997
*
98+
* @param array $values The deserialized body parameters, if any.
11099
* @return void
100+
* @throws \InvalidArgumentException For $values that cannot be accepted.
111101
*/
112-
public function setBodyParams($values);
102+
public function setBodyParams(array $values);
113103

114104
/**
115-
* Retrieve parameters matched during routing.
105+
* Retrieve attributes derived from the request.
116106
*
117107
* If a router or similar is used to match against the path and/or request,
118-
* this method can be used to retrieve the results, so long as those
119-
* results can be represented as an array or array-like object.
108+
* this method MAY be used to retrieve the results, so long as those
109+
* results can be represented as an array.
120110
*
121-
* @return array|\ArrayAccess Path parameters matched by routing
111+
* @return array Attributes derived from the request.
122112
*/
123-
public function getPathParams();
113+
public function getAttributes();
124114

125115
/**
126-
* Set parameters discovered by matching that path
116+
* Set attributes derived from the request
127117
*
128118
* If a router or similar is used to match against the path and/or request,
129-
* this method can be used to inject the request with the results, so long
130-
* as those results can be represented as an array or array-like object.
131-
*
132-
* @param array|\ArrayAccess $values Path parameters matched by routing
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.
133121
*
122+
* @param array $attributes Attributes derived from the request.
134123
* @return void
135124
*/
136-
public function setPathParams(array $values);
125+
public function setAttributes(array $attributes);
137126
}

src/MessageInterface.php

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
/**
66
* HTTP messages consist of requests from a client to a server and responses
7-
* from a server to a client.
7+
* from a server to a client. This interface defines the methods common to
8+
* each.
9+
*
10+
* @link http://www.ietf.org/rfc/rfc7230.txt
11+
* @link http://www.ietf.org/rfc/rfc7231.txt
812
*/
913
interface MessageInterface
1014
{
@@ -24,7 +28,6 @@ public function getProtocolVersion();
2428
* "1.1", "1.0").
2529
*
2630
* @param string $version HTTP protocol version
27-
*
2831
* @return void
2932
*/
3033
public function setProtocolVersion($version);
@@ -43,9 +46,7 @@ public function getBody();
4346
* remove the existing body.
4447
*
4548
* @param StreamableInterface|null $body Body.
46-
*
4749
* @return void
48-
*
4950
* @throws \InvalidArgumentException When the body is not valid.
5051
*/
5152
public function setBody(StreamableInterface $body = null);
@@ -61,15 +62,22 @@ public function setBody(StreamableInterface $body = null);
6162
* echo $name . ": " . implode(", ", $values);
6263
* }
6364
*
64-
* @return array Returns an associative array of the message's headers.
65+
* // Emit headers iteratively:
66+
* foreach ($message->getHeaders() as $name => $values) {
67+
* foreach ($values as $value) {
68+
* header(sprintf('%s: %s', $name, $value), false);
69+
* }
70+
* }
71+
*
72+
* @return array Returns an associative array of the message's headers. Each
73+
* key MUST be a header name, and each value MUST be an array of strings.
6574
*/
6675
public function getHeaders();
6776

6877
/**
6978
* Checks if a header exists by the given case-insensitive name.
7079
*
7180
* @param string $header Case-insensitive header name.
72-
*
7381
* @return bool Returns true if any header names match the given header
7482
* name using a case-insensitive string comparison. Returns false if
7583
* no matching header name is found in the message.
@@ -84,7 +92,6 @@ public function hasHeader($header);
8492
* a comma.
8593
*
8694
* @param string $header Case-insensitive header name.
87-
*
8895
* @return string
8996
*/
9097
public function getHeader($header);
@@ -93,7 +100,6 @@ public function getHeader($header);
93100
* Retrieves a header by the given case-insensitive name as an array of strings.
94101
*
95102
* @param string $header Case-insensitive header name.
96-
*
97103
* @return string[]
98104
*/
99105
public function getHeaderAsArray($header);
@@ -106,64 +112,29 @@ public function getHeaderAsArray($header);
106112
* or an array of strings.
107113
*
108114
* @param string $header Header name
109-
* @param string|string[]|object|object[] $value Header value(s). Values may
110-
* be objects as long as they
111-
* can be cast to strings.
112-
*
115+
* @param string|string[] $value Header value(s).
113116
* @return void
117+
* @throws \InvalidArgumentException for invalid header names or values.
114118
*/
115119
public function setHeader($header, $value);
116120

117-
/**
118-
* Sets headers, replacing any headers that have already been set on the message.
119-
*
120-
* The array keys MUST be a string. Each array value MUST be either a string
121-
* or object, or array of strings and/or objects; any object used as a
122-
* header value MUST be able to be cast to a string.
123-
*
124-
* @param array $headers Headers to set.
125-
*
126-
* @return void
127-
*/
128-
public function setHeaders(array $headers);
129-
130121
/**
131122
* Appends a header value for the specified header.
132123
*
133124
* Existing values for the specified header will be maintained. The new
134-
* value will be appended to the existing list.
125+
* value(s) will be appended to the existing list.
135126
*
136127
* @param string $header Header name to add
137-
* @param string|object $value Value of the header; object is allowed if it
138-
* can be cast to a string.
139-
*
128+
* @param string|string[] $value Header value(s).
140129
* @return void
130+
* @throws \InvalidArgumentException for invalid header names or values.
141131
*/
142132
public function addHeader($header, $value);
143133

144-
/**
145-
* Merges in an associative array of headers.
146-
*
147-
* Each array key MUST be a string representing the case-insensitive name
148-
* of a header. Each value MUST be either a string or object, or array of
149-
* strings and/or objects; any object used as a header value MUST be able
150-
* to be cast to a string.
151-
*
152-
* For each value, the value is appended to any existing header of the same
153-
* name, or, if a header does not already exist by the given name, then the
154-
* header is added.
155-
*
156-
* @param array $headers Associative array of headers to add to the message
157-
*
158-
* @return void
159-
*/
160-
public function addHeaders(array $headers);
161-
162134
/**
163135
* Remove a specific header by case-insensitive name.
164136
*
165137
* @param string $header HTTP header to remove
166-
*
167138
* @return void
168139
*/
169140
public function removeHeader($header);

src/RequestInterface.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,40 @@
33
namespace Psr\Http\Message;
44

55
/**
6-
* A HTTP request message.
7-
* @link http://tools.ietf.org/html/rfc2616#section-5
6+
* An HTTP request message.
7+
*
8+
* @link http://tools.ietf.org/html/rfc7230#section-3
89
*/
910
interface RequestInterface extends MessageInterface
1011
{
1112
/**
12-
* Gets the HTTP method of the request.
13+
* Retrieves the HTTP method of the request.
1314
*
1415
* @return string Returns the request method.
1516
*/
1617
public function getMethod();
1718

1819
/**
19-
* Sets the method to be performed on the resource identified by the Request-URI.
20+
* Sets the HTTP method to be performed on the resource identified by the
21+
* Request-URI.
2022
*
2123
* While HTTP method names are typically all uppercase characters, HTTP
2224
* method names are case-sensitive and thus implementations SHOULD NOT
2325
* modify the given string.
2426
*
2527
* @param string $method Case-insensitive method.
26-
*
2728
* @return void
29+
* @throws \InvalidArgumentException for invalid HTTP methods.
2830
*/
2931
public function setMethod($method);
3032

3133
/**
32-
* Gets the absolute request URL.
34+
* Retrieves the absolute request URL.
3335
*
36+
* @link http://tools.ietf.org/html/rfc3986#section-4.3
3437
* @return string|object Returns the URL as a string, or an object that
3538
* implements the `__toString()` method. The URL must be an absolute URI
3639
* as specified in RFC 3986.
37-
*
38-
* @link http://tools.ietf.org/html/rfc3986#section-4.3
3940
*/
4041
public function getUrl();
4142

@@ -46,12 +47,10 @@ public function getUrl();
4647
* `__toString()` method. The URL must be an absolute URI as specified
4748
* in RFC 3986.
4849
*
50+
* @link http://tools.ietf.org/html/rfc3986#section-4.3
4951
* @param string|object $url Request URL.
50-
*
5152
* @return void
52-
*
5353
* @throws \InvalidArgumentException If the URL is invalid.
54-
* @link http://tools.ietf.org/html/rfc3986#section-4.3
5554
*/
5655
public function setUrl($url);
5756
}

0 commit comments

Comments
 (0)