Skip to content

Commit 488c9fc

Browse files
committed
Full mutability
This patch essentially reverts the interfaces to the original set: - `StreamableInterface` - `MessageInterface` - `RequestInterface` - `ResponseInterface` - `ServerRequestInterface` (originally `IncomingRequestInterface`) Most properties are now mutable, with the exception of server and file parameters in the server request interface (as these are considered non-computable). Additionally, this patch adds a new property to the request interface: the base URL. This property is intended to store the scheme and host, and optionally authentication and port. The "url" is now considered to ONLY store the path + query string.
1 parent 18619ee commit 488c9fc

File tree

6 files changed

+231
-266
lines changed

6 files changed

+231
-266
lines changed

src/IncomingResponseInterface.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/MessageInterface.php

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ interface MessageInterface
2222
public function getProtocolVersion();
2323

2424
/**
25-
* Gets the body of the message.
25+
* Set the HTTP protocol version.
2626
*
27-
* @return StreamableInterface|null Returns the body, or null if not set.
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
2832
*/
29-
public function getBody();
33+
public function setProtocolVersion($version);
3034

3135
/**
3236
* Gets all message headers.
@@ -82,5 +86,58 @@ public function getHeader($header);
8286
* @param string $header Case-insensitive header name.
8387
* @return string[]
8488
*/
85-
public function getHeaderAsArray($header);
89+
public function getHeaderLines($header);
90+
91+
/**
92+
* Sets a header, replacing any existing values of any headers with the
93+
* same case-insensitive name.
94+
*
95+
* The header name is case-insensitive. The header values MUST be a string
96+
* or an array of strings.
97+
*
98+
* @param string $header Header name
99+
* @param string|string[] $value Header value(s).
100+
* @return void
101+
* @throws \InvalidArgumentException for invalid header names or values.
102+
*/
103+
public function setHeader($header, $value);
104+
105+
/**
106+
* Appends a header value for the specified header.
107+
*
108+
* Existing values for the specified header will be maintained. The new
109+
* value(s) will be appended to the existing list.
110+
*
111+
* @param string $header Header name to add
112+
* @param string|string[] $value Header value(s).
113+
* @return void
114+
* @throws \InvalidArgumentException for invalid header names or values.
115+
*/
116+
public function addHeader($header, $value);
117+
118+
/**
119+
* Remove a specific header by case-insensitive name.
120+
*
121+
* @param string $header HTTP header to remove
122+
* @return void
123+
*/
124+
public function removeHeader($header);
125+
126+
/**
127+
* Gets the body of the message.
128+
*
129+
* @return StreamableInterface|null Returns the body, or null if not set.
130+
*/
131+
public function getBody();
132+
133+
/**
134+
* Sets the body of the message.
135+
*
136+
* The body MUST be a StreamableInterface object.
137+
*
138+
* @param StreamableInterface $body Body.
139+
* @return void
140+
* @throws \InvalidArgumentException When the body is not valid.
141+
*/
142+
public function setBody(StreamableInterface $body);
86143
}

src/OutgoingRequestInterface.php

Lines changed: 0 additions & 121 deletions
This file was deleted.

src/RequestInterface.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace Psr\Http\Message;
4+
5+
/**
6+
* Representation of an outgoing, client-side request.
7+
*
8+
* Per the HTTP specification, this interface includes both accessors for
9+
* and mutators for the following:
10+
*
11+
* - Protocol version
12+
* - HTTP method
13+
* - URL
14+
* - Headers
15+
* - Message body
16+
*
17+
* As the request CAN be built iteratively, the interface allows
18+
* mutability of all properties.
19+
*/
20+
interface RequestInterface extends MessageInterface
21+
{
22+
/**
23+
* Retrieves the HTTP method of the request.
24+
*
25+
* @return string Returns the request method.
26+
*/
27+
public function getMethod();
28+
29+
/**
30+
* Sets the HTTP method to be performed on the resource identified by the
31+
* Request-URI.
32+
*
33+
* While HTTP method names are typically all uppercase characters, HTTP
34+
* method names are case-sensitive and thus implementations SHOULD NOT
35+
* modify the given string.
36+
*
37+
* @param string $method Case-insensitive method.
38+
* @return void
39+
* @throws \InvalidArgumentException for invalid HTTP methods.
40+
*/
41+
public function setMethod($method);
42+
43+
/**
44+
* Retrieves the base request URL.
45+
*
46+
* The base URL consists of:
47+
*
48+
* - scheme
49+
* - authentication (if any)
50+
* - server name/host
51+
* - port (if non-standard)
52+
*
53+
* This method is provided for convenience, particularly when considering
54+
* server-side requests, where data such as the scheme and server name may
55+
* need to be computed from more than one environmental variable.
56+
*
57+
* @link http://tools.ietf.org/html/rfc3986#section-4.3
58+
* @return string Returns the base URL as a string. The URL MUST include
59+
* the scheme and host; if the port is non-standard for the scheme,
60+
* the port MUST be included; authentication data MAY be provided.
61+
*/
62+
public function getBaseUrl();
63+
64+
/**
65+
* Sets the base request URL.
66+
*
67+
* The base URL MUST be a string, and MUST include the scheme and host.
68+
*
69+
* If the port is non-standard for the scheme, the port MUST be provided.
70+
*
71+
* Authentication data MAY be provided.
72+
*
73+
* If path, query string, or URL fragment are provided they SHOULD be
74+
* stripped; optionally, an error MAY be raised in such situations.
75+
*
76+
* @link http://tools.ietf.org/html/rfc3986#section-4.3
77+
* @param string $url Base request URL.
78+
* @return void
79+
* @throws \InvalidArgumentException If the URL is invalid.
80+
*/
81+
public function setBaseUrl($url);
82+
83+
/**
84+
* Retrieves the request URL.
85+
*
86+
* The request URL is the same value as REQUEST_URI: the path and query
87+
* string ONLY.
88+
*
89+
* @link http://tools.ietf.org/html/rfc7230#section-5.3
90+
* @return string Returns the URL as a string. The URL MUST be an
91+
* origin-form (path + query string), per RFC 7230 section 5.3
92+
*/
93+
public function getUrl();
94+
95+
/**
96+
* Sets the request URL.
97+
*
98+
* The URL MUST be a string. The URL SHOULD be an origin-form (path + query
99+
* string) per RFC 7230 section 5.3; if other URL parts are present, the
100+
* method MUST raise an exception OR remove those parts.
101+
*
102+
* @link http://tools.ietf.org/html/rfc7230#section-5.3
103+
* @param string $url Request URL, with path and optionally query string.
104+
* @return void
105+
* @throws \InvalidArgumentException If the URL is invalid.
106+
*/
107+
public function setUrl($url);
108+
}

0 commit comments

Comments
 (0)