Skip to content

Commit facd2d7

Browse files
committed
Renamed all mutator methods
Since messages are immutable, and to avoid confusion with regular setters that change internal state, I've renamed all setter methods to use alternate verbiage. "with" is an accepted standard, and this was used whenever possible, with the following exceptions: - `addHeader` was renamed to `withAddedHeader()`. - `removeHeader` was renamed to `withoutHeader()`.
1 parent 4ba875b commit facd2d7

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

src/MessageInterface.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface MessageInterface
2626
public function getProtocolVersion();
2727

2828
/**
29-
* Set the HTTP protocol version.
29+
* Create a new 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").
@@ -38,7 +38,7 @@ public function getProtocolVersion();
3838
* @param string $version HTTP protocol version
3939
* @return MessageInterface
4040
*/
41-
public function setProtocolVersion($version);
41+
public function withProtocolVersion($version);
4242

4343
/**
4444
* Gets all message headers.
@@ -97,8 +97,8 @@ public function getHeader($header);
9797
public function getHeaderLines($header);
9898

9999
/**
100-
* Sets a header, replacing any existing values of any headers with the
101-
* same case-insensitive name.
100+
* Create a new instance with the provided header, replacing any existing
101+
* values of any headers with the same case-insensitive name.
102102
*
103103
* The header name is case-insensitive. The header values MUST be a string
104104
* or an array of strings.
@@ -112,10 +112,11 @@ public function getHeaderLines($header);
112112
* @return MessageInterface
113113
* @throws \InvalidArgumentException for invalid header names or values.
114114
*/
115-
public function setHeader($header, $value);
115+
public function withHeader($header, $value);
116116

117117
/**
118-
* Appends a header value for the specified header.
118+
* Creates a new instance, with the specified header appended with the
119+
* given value.
119120
*
120121
* Existing values for the specified header will be maintained. The new
121122
* value(s) will be appended to the existing list.
@@ -129,10 +130,12 @@ public function setHeader($header, $value);
129130
* @return MessageInterface
130131
* @throws \InvalidArgumentException for invalid header names or values.
131132
*/
132-
public function addHeader($header, $value);
133+
public function withAddedHeader($header, $value);
133134

134135
/**
135-
* Remove a specific header by case-insensitive name.
136+
* Creates a new instance, without the specified header.
137+
*
138+
* Header resolution MUST be done without case-insensitivity.
136139
*
137140
* This method MUST be implemented in such a way as to retain the
138141
* immutability of the message, and MUST return a new instance that removes
@@ -141,7 +144,7 @@ public function addHeader($header, $value);
141144
* @param string $header HTTP header to remove
142145
* @return MessageInterface
143146
*/
144-
public function removeHeader($header);
147+
public function withoutHeader($header);
145148

146149
/**
147150
* Gets the body of the message.
@@ -151,7 +154,7 @@ public function removeHeader($header);
151154
public function getBody();
152155

153156
/**
154-
* Sets the body of the message.
157+
* Create a new instance, with the specified message body.
155158
*
156159
* The body MUST be a StreamableInterface object.
157160
*
@@ -163,5 +166,5 @@ public function getBody();
163166
* @return MessageInterface
164167
* @throws \InvalidArgumentException When the body is not valid.
165168
*/
166-
public function setBody(StreamableInterface $body);
169+
public function withBody(StreamableInterface $body);
167170
}

src/RequestInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ interface RequestInterface extends MessageInterface
2828
public function getMethod();
2929

3030
/**
31-
* Sets the HTTP method to be performed on the resource identified by the
32-
* Request-URI.
31+
* Create a new instance with the provided HTTP method to perform on the
32+
* resource identified by the Request-URI.
3333
*
3434
* While HTTP method names are typically all uppercase characters, HTTP
3535
* method names are case-sensitive and thus implementations SHOULD NOT
@@ -43,7 +43,7 @@ public function getMethod();
4343
* @return RequestInterface
4444
* @throws \InvalidArgumentException for invalid HTTP methods.
4545
*/
46-
public function setMethod($method);
46+
public function withMethod($method);
4747

4848
/**
4949
* Retrieves the absolute URI.
@@ -70,7 +70,7 @@ public function setMethod($method);
7070
public function getAbsoluteUri();
7171

7272
/**
73-
* Sets the absolute URI of the request.
73+
* Create a new instance with the provided absolute URI.
7474
*
7575
* The absolute URI MUST be a string, and MUST include the scheme and host.
7676
*
@@ -92,7 +92,7 @@ public function getAbsoluteUri();
9292
* @return RequestInterface
9393
* @throws \InvalidArgumentException If the URI is invalid.
9494
*/
95-
public function setAbsoluteUri($uri);
95+
public function withAbsoluteUri($uri);
9696

9797
/**
9898
* Retrieves the request URL.
@@ -106,7 +106,7 @@ public function setAbsoluteUri($uri);
106106
public function getUrl();
107107

108108
/**
109-
* Sets the request URL.
109+
* Create a new instance with the specified request URL.
110110
*
111111
* The URL MUST be a string. The URL SHOULD be an origin-form (path + query
112112
* string) per RFC 7230 section 5.3; if other URL parts are present, the
@@ -124,5 +124,5 @@ public function getUrl();
124124
* @return RequestInterface
125125
* @throws \InvalidArgumentException If the URL is invalid.
126126
*/
127-
public function setUrl($url);
127+
public function withUrl($url);
128128
}

src/ResponseInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ interface ResponseInterface extends MessageInterface
3030
public function getStatusCode();
3131

3232
/**
33-
* Sets the status code, and optionally reason phrase, of this response.
33+
* Create a new instance with the specified status code, and optionally
34+
* reason phrase, for the response.
3435
*
3536
* If no Reason-Phrase is specified, implementations MAY choose to default
3637
* to the RFC 7231 or IANA recommended reason phrase for the response's
@@ -49,7 +50,7 @@ public function getStatusCode();
4950
* @return ResponseInterface
5051
* @throws \InvalidArgumentException For invalid status code arguments.
5152
*/
52-
public function setStatus($code, $reasonPhrase = null);
53+
public function withStatus($code, $reasonPhrase = null);
5354

5455
/**
5556
* Gets the response Reason-Phrase, a short textual description of the Status-Code.

src/ServerRequestInterface.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ public function getServerParams();
6666
public function getCookieParams();
6767

6868
/**
69-
* Set cookies.
70-
*
71-
* Set cookies sent by the client to the server.
69+
* Create a new instance with the specified cookies.
7270
*
7371
* The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST
7472
* be compatible with the structure of $_COOKIE. Typically, this data will
@@ -81,7 +79,7 @@ public function getCookieParams();
8179
* @param array $cookies Array of key/value pairs representing cookies.
8280
* @return ServerRequestInterface
8381
*/
84-
public function setCookieParams(array $cookies);
82+
public function withCookieParams(array $cookies);
8583

8684
/**
8785
* Retrieve query string arguments.
@@ -98,7 +96,7 @@ public function setCookieParams(array $cookies);
9896
public function getQueryParams();
9997

10098
/**
101-
* Set query string arguments.
99+
* Create a new instance with the specified query string arguments.
102100
*
103101
* These values SHOULD remain immutable over the course of the incoming
104102
* request. They MAY be injected during instantiation, such as from PHP's
@@ -119,7 +117,7 @@ public function getQueryParams();
119117
* $_GET.
120118
* @return ServerRequestInterface
121119
*/
122-
public function setQueryParams(array $query);
120+
public function withQueryParams(array $query);
123121

124122
/**
125123
* Retrieve the upload file metadata.
@@ -146,7 +144,7 @@ public function getFileParams();
146144
public function getBodyParams();
147145

148146
/**
149-
* Set parameters provided in the request body.
147+
* Create a new instance with the specified body parameters.
150148
*
151149
* These MAY be injected during instantiation from PHP's $_POST
152150
* superglobal. The data IS NOT REQUIRED to come from $_POST, but MUST be
@@ -163,7 +161,7 @@ public function getBodyParams();
163161
* @param array $params The deserialized body parameters.
164162
* @return ServerRequestInterface
165163
*/
166-
public function setBodyParams(array $params);
164+
public function withBodyParams(array $params);
167165

168166
/**
169167
* Retrieve attributes derived from the request.
@@ -193,7 +191,8 @@ public function getAttributes();
193191
public function getAttribute($attribute, $default = null);
194192

195193
/**
196-
* Set attributes derived from the request.
194+
* Create a new instance with the specified attributes as derived from the
195+
* request.
197196
*
198197
* This method allows setting request attributes, as described in
199198
* getAttributes().
@@ -206,10 +205,10 @@ public function getAttribute($attribute, $default = null);
206205
* @param array $attributes Attributes derived from the request.
207206
* @return ServerRequestInterface
208207
*/
209-
public function setAttributes(array $attributes);
208+
public function withAttributes(array $attributes);
210209

211210
/**
212-
* Set a single derived request attribute.
211+
* Create a new instance with the specified derived request attribute.
213212
*
214213
* This method allows setting a single derived request attribute as
215214
* described in getAttributes().
@@ -223,5 +222,5 @@ public function setAttributes(array $attributes);
223222
* @param mixed $value The value of the attribute.
224223
* @return ServerRequestInterface
225224
*/
226-
public function setAttribute($attribute, $value);
225+
public function withAttribute($attribute, $value);
227226
}

0 commit comments

Comments
 (0)