Skip to content

Commit 809419e

Browse files
author
Paul M. Jones
committed
Merge pull request #43 from weierophinney/hotfix/sync-with-spec
Update to latest PSR-7 version
2 parents 9723465 + f22d9b6 commit 809419e

7 files changed

+49
-90
lines changed

src/MessageInterface.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ public function hasHeader($name);
9494
public function getHeader($name);
9595

9696
/**
97-
* Retrieves the line for a single header, with the header values as a
98-
* comma-separated string.
97+
* Retrieves a comma-separated string of the values for a single header.
9998
*
10099
* This method returns all of the header values of the given
101100
* case-insensitive header name as a string concatenated together using
@@ -106,18 +105,17 @@ public function getHeader($name);
106105
* and supply your own delimiter when concatenating.
107106
*
108107
* If the header does not appear in the message, this method MUST return
109-
* a null value.
108+
* an empty string.
110109
*
111110
* @param string $name Case-insensitive header field name.
112-
* @return string|null A string of values as provided for the given header
111+
* @return string A string of values as provided for the given header
113112
* concatenated together using a comma. If the header does not appear in
114-
* the message, this method MUST return a null value.
113+
* the message, this method MUST return an empty string.
115114
*/
116115
public function getHeaderLine($name);
117116

118117
/**
119-
* Return an instance with the provided header, replacing any existing
120-
* values of any headers with the same case-insensitive name.
118+
* Return an instance with the provided value replacing the specified header.
121119
*
122120
* While header names are case-insensitive, the casing of the header will
123121
* be preserved by this function, and returned from getHeaders().
@@ -134,8 +132,7 @@ public function getHeaderLine($name);
134132
public function withHeader($name, $value);
135133

136134
/**
137-
* Return an instance with the specified header appended with the
138-
* given value.
135+
* Return an instance with the specified header appended with the given value.
139136
*
140137
* Existing values for the specified header will be maintained. The new
141138
* value(s) will be appended to the existing list. If the header did not

src/RequestInterface.php

+16-66
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,15 @@
1414
* - Headers
1515
* - Message body
1616
*
17+
* During construction, implementations MUST attempt to set the Host header from
18+
* a provided URI if no Host header is provided.
19+
*
1720
* Requests are considered immutable; all methods that might change state MUST
1821
* be implemented such that they retain the internal state of the current
1922
* message and return an instance that contains the changed state.
2023
*/
2124
interface RequestInterface extends MessageInterface
2225
{
23-
/**
24-
* Extends MessageInterface::getHeaders() to provide request-specific
25-
* behavior.
26-
*
27-
* Retrieves all message headers.
28-
*
29-
* This method acts exactly like MessageInterface::getHeaders(), with one
30-
* behavioral change: if the Host header has not been previously set, the
31-
* method MUST attempt to pull the host component of the composed URI, if
32-
* present.
33-
*
34-
* @see MessageInterface::getHeaders()
35-
* @see UriInterface::getHost()
36-
* @return array Returns an associative array of the message's headers. Each
37-
* key MUST be a header name, and each value MUST be an array of strings.
38-
*/
39-
public function getHeaders();
40-
41-
/**
42-
* Extends MessageInterface::getHeader() to provide request-specific
43-
* behavior.
44-
*
45-
* This method acts exactly like MessageInterface::getHeader(), with
46-
* one behavioral change: if the Host header is requested, but has
47-
* not been previously set, the method MUST attempt to pull the host
48-
* component of the composed URI, if present.
49-
*
50-
* @see MessageInterface::getHeader()
51-
* @see UriInterface::getHost()
52-
* @param string $name Case-insensitive header field name.
53-
* @return string[] An array of string values as provided for the given
54-
* header. If the header does not appear in the message, this method MUST
55-
* return an empty array.
56-
*/
57-
public function getHeader($name);
58-
59-
/**
60-
* Extends MessageInterface::getHeaderLines() to provide request-specific
61-
* behavior.
62-
*
63-
* This method returns all of the header values of the given
64-
* case-insensitive header name as a string concatenated together using
65-
* a comma.
66-
*
67-
* This method acts exactly like MessageInterface::getHeaderLines(), with
68-
* one behavioral change: if the Host header is requested, but has
69-
* not been previously set, the method MUST attempt to pull the host
70-
* component of the composed URI, if present.
71-
*
72-
* @see MessageInterface::getHeaderLine()
73-
* @see UriInterface::getHost()
74-
* @param string $name Case-insensitive header field name.
75-
* @return string|null A string of values as provided for the given header
76-
* concatenated together using a comma. If the header does not appear in
77-
* the message, this method MUST return a null value.
78-
*/
79-
public function getHeaderLine($name);
80-
8126
/**
8227
* Retrieves the message's request target.
8328
*
@@ -133,7 +78,7 @@ public function getMethod();
13378
* immutability of the message, and MUST return an instance that has the
13479
* changed request method.
13580
*
136-
* @param string $method Case-insensitive method.
81+
* @param string $method Case-sensitive method.
13782
* @return self
13883
* @throws \InvalidArgumentException for invalid HTTP methods.
13984
*/
@@ -153,18 +98,23 @@ public function getUri();
15398
/**
15499
* Returns an instance with the provided URI.
155100
*
156-
* This method will update the Host header of the returned request by
101+
* This method MUST update the Host header of the returned request by
157102
* default if the URI contains a host component. If the URI does not
158-
* contain a host component, any pre-existing Host header will be carried
103+
* contain a host component, any pre-existing Host header MUST be carried
159104
* over to the returned request.
160105
*
161106
* You can opt-in to preserving the original state of the Host header by
162107
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
163-
* `true`, the returned request will not update the Host header of the
164-
* returned message -- even if the message contains no Host header. This
165-
* means that a call to `getHeader('Host')` on the original request MUST
166-
* equal the return value of a call to `getHeader('Host')` on the returned
167-
* request.
108+
* `true`, this method interacts with the Host header in the following ways:
109+
*
110+
* - If the the Host header is missing or empty, and the new URI contains
111+
* a host component, this method MUST update the Host header in the returned
112+
* request.
113+
* - If the Host header is missing or empty, and the new URI does not contain a
114+
* host component, this method MUST NOT update the Host header in the returned
115+
* request.
116+
* - If a Host header is present and non-empty, this method MUST NOT update
117+
* the Host header in the returned request.
168118
*
169119
* This method MUST be implemented in such a way as to retain the
170120
* immutability of the message, and MUST return an instance that has the

src/ResponseInterface.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ interface ResponseInterface extends MessageInterface
3030
public function getStatusCode();
3131

3232
/**
33-
* Return an instance with the specified status code, and optionally
34-
* reason phrase, for the response.
33+
* Return an instance with the specified status code and, optionally, reason phrase.
3534
*
3635
* If no reason phrase is specified, implementations MAY choose to default
3736
* to the RFC 7231 or IANA recommended reason phrase for the response's
@@ -44,17 +43,16 @@ public function getStatusCode();
4443
* @link http://tools.ietf.org/html/rfc7231#section-6
4544
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
4645
* @param int $code The 3-digit integer result code to set.
47-
* @param null|string $reasonPhrase The reason phrase to use with the
46+
* @param string $reasonPhrase The reason phrase to use with the
4847
* provided status code; if none is provided, implementations MAY
4948
* use the defaults as suggested in the HTTP specification.
5049
* @return self
5150
* @throws \InvalidArgumentException For invalid status code arguments.
5251
*/
53-
public function withStatus($code, $reasonPhrase = null);
52+
public function withStatus($code, $reasonPhrase = '');
5453

5554
/**
56-
* Gets the response reason phrase, a short textual description of the
57-
* status code.
55+
* Gets the response reason phrase associated with the status code.
5856
*
5957
* Because a reason phrase is not a required element in a response
6058
* status line, the reason phrase value MAY be null. Implementations MAY
@@ -64,7 +62,7 @@ public function withStatus($code, $reasonPhrase = null);
6462
*
6563
* @link http://tools.ietf.org/html/rfc7231#section-6
6664
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
67-
* @return string|null Reason phrase, or null if unknown.
65+
* @return string Reason phrase; must return an empty string if none present.
6866
*/
6967
public function getReasonPhrase();
7068
}

src/ServerRequestInterface.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function getCookieParams();
7272
* be compatible with the structure of $_COOKIE. Typically, this data will
7373
* be injected at instantiation.
7474
*
75+
* This method MUST NOT update the related Cookie header of the request
76+
* instance, nor related values in the server params.
77+
*
7578
* This method MUST be implemented in such a way as to retain the
7679
* immutability of the message, and MUST return an instance that has the
7780
* updated cookie values.
@@ -241,8 +244,7 @@ public function getAttribute($name, $default = null);
241244
public function withAttribute($name, $value);
242245

243246
/**
244-
* Return an instance that removes the specified derived request
245-
* attribute.
247+
* Return an instance that removes the specified derived request attribute.
246248
*
247249
* This method allows removing a single derived request attribute as
248250
* described in getAttributes().

src/StreamInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function close();
4444
public function detach();
4545

4646
/**
47-
* Get the size of the stream if known
47+
* Get the size of the stream if known.
4848
*
4949
* @return int|null Returns the size in bytes if known, or null if unknown.
5050
*/

src/UploadedFileInterface.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface UploadedFileInterface
2020
* stream_copy_to_stream() (though the result will need to be decorated in a
2121
* native PHP stream wrapper to work with such functions).
2222
*
23-
* If the move() method has been called previously, this method MUST raise
23+
* If the moveTo() method has been called previously, this method MUST raise
2424
* an exception.
2525
*
2626
* @return StreamInterface Stream representation of the uploaded file.
@@ -38,23 +38,30 @@ public function getStream();
3838
* appropriate method (move_uploaded_file(), rename(), or a stream
3939
* operation) to perform the operation.
4040
*
41+
* $targetPath may be an absolute path, or a relative path. If it is a
42+
* relative path, resolution should be the same as used by PHP's rename()
43+
* function.
44+
*
4145
* The original file or stream MUST be removed on completion.
4246
*
4347
* If this method is called more than once, any subsequent calls MUST raise
4448
* an exception.
4549
*
4650
* When used in an SAPI environment where $_FILES is populated, when writing
47-
* files via move(), is_uploaded_file() and move_uploaded_file() SHOULD be
48-
* use to ensure permissions and upload status are verified correctly.
51+
* files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be
52+
* used to ensure permissions and upload status are verified correctly.
53+
*
54+
* If you wish to move to a stream, use getStream(), as SAPI operations
55+
* cannot guarantee writing to stream destinations.
4956
*
5057
* @see http://php.net/is_uploaded_file
5158
* @see http://php.net/move_uploaded_file
52-
* @param string $path Path to which to move the uploaded file.
59+
* @param string $targetPath Path to which to move the uploaded file.
5360
* @throws \InvalidArgumentException if the $path specified is invalid.
5461
* @throws \RuntimeException on any error during the move operation, or on
5562
* the second or subsequent call to the method.
5663
*/
57-
public function move($path);
64+
public function moveTo($targetPath);
5865

5966
/**
6067
* Retrieve the file size.

src/UriInterface.php

+5
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ public function withPort($port);
249249
* rootless (not starting with a slash). Implementations MUST support all
250250
* three syntaxes.
251251
*
252+
* If the path is intended to be domain-relative rather than path relative then
253+
* it must begin with a slash ("/"). Paths not starting with a slash ("/")
254+
* are assumed to be relative to some base path known to the application or
255+
* consumer.
256+
*
252257
* Users can provide both encoded and decoded path characters.
253258
* Implementations ensure the correct encoding as outlined in getPath().
254259
*

0 commit comments

Comments
 (0)