Skip to content

Commit 116ee92

Browse files
author
Paul M. Jones
committed
Merge pull request #38 from weierophinney/feature/post-draft-2
Bring interfaces up-to-date with php-fig/fig-standards@b740164
2 parents 7c361ae + f3218d1 commit 116ee92

7 files changed

+403
-191
lines changed

src/MessageInterface.php

+42-33
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Messages are considered immutable; all methods that might change state MUST
1111
* be implemented such that they retain the internal state of the current
12-
* message and return a new instance that contains the changed state.
12+
* message and return an instance that contains the changed state.
1313
*
1414
* @link http://www.ietf.org/rfc/rfc7230.txt
1515
* @link http://www.ietf.org/rfc/rfc7231.txt
@@ -26,13 +26,13 @@ interface MessageInterface
2626
public function getProtocolVersion();
2727

2828
/**
29-
* Create a new instance with the specified HTTP protocol version.
29+
* Return an instance with the specified HTTP protocol version.
3030
*
3131
* The version string MUST contain only the HTTP version number (e.g.,
3232
* "1.1", "1.0").
3333
*
3434
* This method MUST be implemented in such a way as to retain the
35-
* immutability of the message, and MUST return a new instance that has the
35+
* immutability of the message, and MUST return an instance that has the
3636
* new protocol version.
3737
*
3838
* @param string $version HTTP protocol version
@@ -41,7 +41,7 @@ public function getProtocolVersion();
4141
public function withProtocolVersion($version);
4242

4343
/**
44-
* Retrieves all message headers.
44+
* Retrieves all message header values.
4545
*
4646
* The keys represent the header name as it will be sent over the wire, and
4747
* each value is an array of strings associated with the header.
@@ -62,7 +62,8 @@ public function withProtocolVersion($version);
6262
* exact case in which headers were originally specified.
6363
*
6464
* @return array Returns an associative array of the message's headers. Each
65-
* key MUST be a header name, and each value MUST be an array of strings.
65+
* key MUST be a header name, and each value MUST be an array of strings
66+
* for that header.
6667
*/
6768
public function getHeaders();
6869

@@ -77,44 +78,52 @@ public function getHeaders();
7778
public function hasHeader($name);
7879

7980
/**
80-
* Retrieve a header by the given case-insensitive name, as a string.
81+
* Retrieves a message header value by the given case-insensitive name.
8182
*
82-
* This method returns all of the header values of the given
83-
* case-insensitive header name as a string concatenated together using
84-
* a comma.
83+
* This method returns an array of all the header values of the given
84+
* case-insensitive header name.
8585
*
86-
* NOTE: Not all header values may be appropriately represented using
87-
* comma concatenation. For such headers, use getHeaderLines() instead
88-
* and supply your own delimiter when concatenating.
89-
*
90-
* If the header did not appear in the message, this method should return
91-
* a null value.
86+
* If the header does not appear in the message, this method MUST return an
87+
* empty array.
9288
*
9389
* @param string $name Case-insensitive header field name.
94-
* @return string|null
90+
* @return string[] An array of string values as provided for the given
91+
* header. If the header does not appear in the message, this method MUST
92+
* return an empty array.
9593
*/
9694
public function getHeader($name);
9795

9896
/**
99-
* Retrieves a header by the given case-insensitive name as an array of strings.
100-
*
101-
* If the header did not appear in the message, this method should return an
102-
* empty array.
97+
* Retrieves the line for a single header, with the header values as a
98+
* comma-separated string.
99+
*
100+
* This method returns all of the header values of the given
101+
* case-insensitive header name as a string concatenated together using
102+
* a comma.
103+
*
104+
* NOTE: Not all header values may be appropriately represented using
105+
* comma concatenation. For such headers, use getHeader() instead
106+
* and supply your own delimiter when concatenating.
107+
*
108+
* If the header does not appear in the message, this method MUST return
109+
* a null value.
103110
*
104111
* @param string $name Case-insensitive header field name.
105-
* @return string[]
112+
* @return string|null A string of values as provided for the given header
113+
* concatenated together using a comma. If the header does not appear in
114+
* the message, this method MUST return a null value.
106115
*/
107-
public function getHeaderLines($name);
116+
public function getHeaderLine($name);
108117

109118
/**
110-
* Create a new instance with the provided header, replacing any existing
119+
* Return an instance with the provided header, replacing any existing
111120
* values of any headers with the same case-insensitive name.
112121
*
113122
* While header names are case-insensitive, the casing of the header will
114123
* be preserved by this function, and returned from getHeaders().
115124
*
116125
* This method MUST be implemented in such a way as to retain the
117-
* immutability of the message, and MUST return a new instance that has the
126+
* immutability of the message, and MUST return an instance that has the
118127
* new and/or updated header and value.
119128
*
120129
* @param string $name Case-insensitive header field name.
@@ -125,15 +134,15 @@ public function getHeaderLines($name);
125134
public function withHeader($name, $value);
126135

127136
/**
128-
* Creates a new instance, with the specified header appended with the
137+
* Return an instance with the specified header appended with the
129138
* given value.
130139
*
131140
* Existing values for the specified header will be maintained. The new
132141
* value(s) will be appended to the existing list. If the header did not
133142
* exist previously, it will be added.
134143
*
135144
* This method MUST be implemented in such a way as to retain the
136-
* immutability of the message, and MUST return a new instance that has the
145+
* immutability of the message, and MUST return an instance that has the
137146
* new header and/or value.
138147
*
139148
* @param string $name Case-insensitive header field name to add.
@@ -144,12 +153,12 @@ public function withHeader($name, $value);
144153
public function withAddedHeader($name, $value);
145154

146155
/**
147-
* Creates a new instance, without the specified header.
156+
* Return an instance without the specified header.
148157
*
149158
* Header resolution MUST be done without case-sensitivity.
150159
*
151160
* This method MUST be implemented in such a way as to retain the
152-
* immutability of the message, and MUST return a new instance that removes
161+
* immutability of the message, and MUST return an instance that removes
153162
* the named header.
154163
*
155164
* @param string $name Case-insensitive header field name to remove.
@@ -160,22 +169,22 @@ public function withoutHeader($name);
160169
/**
161170
* Gets the body of the message.
162171
*
163-
* @return StreamableInterface Returns the body as a stream.
172+
* @return StreamInterface Returns the body as a stream.
164173
*/
165174
public function getBody();
166175

167176
/**
168-
* Create a new instance, with the specified message body.
177+
* Return an instance with the specified message body.
169178
*
170-
* The body MUST be a StreamableInterface object.
179+
* The body MUST be a StreamInterface object.
171180
*
172181
* This method MUST be implemented in such a way as to retain the
173182
* immutability of the message, and MUST return a new instance that has the
174183
* new body stream.
175184
*
176-
* @param StreamableInterface $body Body.
185+
* @param StreamInterface $body Body.
177186
* @return self
178187
* @throws \InvalidArgumentException When the body is not valid.
179188
*/
180-
public function withBody(StreamableInterface $body);
189+
public function withBody(StreamInterface $body);
181190
}

src/RequestInterface.php

+36-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* Requests are considered immutable; all methods that might change state MUST
1818
* be implemented such that they retain the internal state of the current
19-
* message and return a new instance that contains the changed state.
19+
* message and return an instance that contains the changed state.
2020
*/
2121
interface RequestInterface extends MessageInterface
2222
{
@@ -28,7 +28,7 @@ interface RequestInterface extends MessageInterface
2828
*
2929
* This method acts exactly like MessageInterface::getHeaders(), with one
3030
* behavioral change: if the Host header has not been previously set, the
31-
* method MUST attempt to pull the host segment of the composed URI, if
31+
* method MUST attempt to pull the host component of the composed URI, if
3232
* present.
3333
*
3434
* @see MessageInterface::getHeaders()
@@ -45,32 +45,38 @@ public function getHeaders();
4545
* This method acts exactly like MessageInterface::getHeader(), with
4646
* one behavioral change: if the Host header is requested, but has
4747
* not been previously set, the method MUST attempt to pull the host
48-
* segment of the composed URI, if present.
48+
* component of the composed URI, if present.
4949
*
5050
* @see MessageInterface::getHeader()
5151
* @see UriInterface::getHost()
5252
* @param string $name Case-insensitive header field name.
53-
* @return string
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.
5456
*/
5557
public function getHeader($name);
5658

5759
/**
5860
* Extends MessageInterface::getHeaderLines() to provide request-specific
5961
* behavior.
6062
*
61-
* Retrieves a header by the given case-insensitive name as an array of strings.
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.
6266
*
6367
* This method acts exactly like MessageInterface::getHeaderLines(), with
6468
* one behavioral change: if the Host header is requested, but has
6569
* not been previously set, the method MUST attempt to pull the host
66-
* segment of the composed URI, if present.
70+
* component of the composed URI, if present.
6771
*
68-
* @see MessageInterface::getHeaderLines()
72+
* @see MessageInterface::getHeaderLine()
6973
* @see UriInterface::getHost()
7074
* @param string $name Case-insensitive header field name.
71-
* @return string[]
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.
7278
*/
73-
public function getHeaderLines($name);
79+
public function getHeaderLine($name);
7480

7581
/**
7682
* Retrieves the message's request target.
@@ -91,15 +97,15 @@ public function getHeaderLines($name);
9197
public function getRequestTarget();
9298

9399
/**
94-
* Create a new instance with a specific request-target.
100+
* Return an instance with the specific request-target.
95101
*
96102
* If the request needs a non-origin-form request-target — e.g., for
97103
* specifying an absolute-form, authority-form, or asterisk-form —
98104
* this method may be used to create an instance with the specified
99105
* request-target, verbatim.
100106
*
101107
* This method MUST be implemented in such a way as to retain the
102-
* immutability of the message, and MUST return a new instance that has the
108+
* immutability of the message, and MUST return an instance that has the
103109
* changed request target.
104110
*
105111
* @link http://tools.ietf.org/html/rfc7230#section-2.7 (for the various
@@ -117,14 +123,14 @@ public function withRequestTarget($requestTarget);
117123
public function getMethod();
118124

119125
/**
120-
* Create a new instance with the provided HTTP method.
126+
* Return an instance with the provided HTTP method.
121127
*
122128
* While HTTP method names are typically all uppercase characters, HTTP
123129
* method names are case-sensitive and thus implementations SHOULD NOT
124130
* modify the given string.
125131
*
126132
* This method MUST be implemented in such a way as to retain the
127-
* immutability of the message, and MUST return a new instance that has the
133+
* immutability of the message, and MUST return an instance that has the
128134
* changed request method.
129135
*
130136
* @param string $method Case-insensitive method.
@@ -145,15 +151,29 @@ public function withMethod($method);
145151
public function getUri();
146152

147153
/**
148-
* Create a new instance with the provided URI.
154+
* Returns an instance with the provided URI.
155+
*
156+
* This method will update the Host header of the returned request by
157+
* 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
159+
* over to the returned request.
160+
*
161+
* You can opt-in to preserving the original state of the Host header by
162+
* 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.
149168
*
150169
* This method MUST be implemented in such a way as to retain the
151-
* immutability of the message, and MUST return a new instance that has the
170+
* immutability of the message, and MUST return an instance that has the
152171
* new UriInterface instance.
153172
*
154173
* @link http://tools.ietf.org/html/rfc3986#section-4.3
155174
* @param UriInterface $uri New request URI to use.
175+
* @param bool $preserveHost Preserve the original state of the Host header.
156176
* @return self
157177
*/
158-
public function withUri(UriInterface $uri);
178+
public function withUri(UriInterface $uri, $preserveHost = false);
159179
}

src/ResponseInterface.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@
1515
*
1616
* Responses are considered immutable; all methods that might change state MUST
1717
* be implemented such that they retain the internal state of the current
18-
* message and return a new instance that contains the changed state.
18+
* message and return an instance that contains the changed state.
1919
*/
2020
interface ResponseInterface extends MessageInterface
2121
{
2222
/**
23-
* Gets the response Status-Code.
23+
* Gets the response status code.
2424
*
25-
* The Status-Code is a 3-digit integer result code of the server's attempt
25+
* The status code is a 3-digit integer result code of the server's attempt
2626
* to understand and satisfy the request.
2727
*
28-
* @return integer Status code.
28+
* @return int Status code.
2929
*/
3030
public function getStatusCode();
3131

3232
/**
33-
* Create a new instance with the specified status code, and optionally
33+
* Return an instance with the specified status code, and optionally
3434
* reason phrase, for the response.
3535
*
36-
* If no Reason-Phrase is specified, implementations MAY choose to default
36+
* If no reason phrase is specified, implementations MAY choose to default
3737
* to the RFC 7231 or IANA recommended reason phrase for the response's
38-
* Status-Code.
38+
* status code.
3939
*
4040
* This method MUST be implemented in such a way as to retain the
41-
* immutability of the message, and MUST return a new instance that has the
41+
* immutability of the message, and MUST return an instance that has the
4242
* updated status and reason phrase.
4343
*
4444
* @link http://tools.ietf.org/html/rfc7231#section-6
4545
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
46-
* @param integer $code The 3-digit integer result code to set.
46+
* @param int $code The 3-digit integer result code to set.
4747
* @param null|string $reasonPhrase The reason phrase to use with the
4848
* provided status code; if none is provided, implementations MAY
4949
* use the defaults as suggested in the HTTP specification.
@@ -53,13 +53,14 @@ public function getStatusCode();
5353
public function withStatus($code, $reasonPhrase = null);
5454

5555
/**
56-
* Gets the response Reason-Phrase, a short textual description of the Status-Code.
56+
* Gets the response reason phrase, a short textual description of the
57+
* status code.
5758
*
58-
* Because a Reason-Phrase is not a required element in a response
59-
* Status-Line, the Reason-Phrase value MAY be null. Implementations MAY
59+
* Because a reason phrase is not a required element in a response
60+
* status line, the reason phrase value MAY be null. Implementations MAY
6061
* choose to return the default RFC 7231 recommended reason phrase (or those
6162
* listed in the IANA HTTP Status Code Registry) for the response's
62-
* Status-Code.
63+
* status code.
6364
*
6465
* @link http://tools.ietf.org/html/rfc7231#section-6
6566
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

0 commit comments

Comments
 (0)