Skip to content

Commit d70356c

Browse files
author
Paul M. Jones
committed
Merge pull request #18 from weierophinney/feature/uri-refactor
Model URIs and move request-target details to Request
2 parents 29f8185 + 15a5588 commit d70356c

File tree

2 files changed

+65
-75
lines changed

2 files changed

+65
-75
lines changed

src/RequestInterface.php

+57-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,58 @@
2020
*/
2121
interface RequestInterface extends MessageInterface
2222
{
23+
/**
24+
* Retrieves the message's request line.
25+
*
26+
* Retrieves the message's request line either as it will appear (for
27+
* clients), as it appeared at request (for servers), or as it was
28+
* specified for the instance (see withRequestLine()).
29+
*
30+
* This method MUST return a string of the form:
31+
*
32+
* <code>
33+
* HTTP_METHOD REQUEST_TARGET HTTP/PROTOCOL_VERSION
34+
* </code>
35+
*
36+
* If the request line is calculated at method execution (i.e., not from
37+
* a value set on the instance), the request-target MUST be in origin-form.
38+
*
39+
* If any aspect of the request line is unknown, it MUST raise an
40+
* exception.
41+
*
42+
* @return string
43+
* @throws \RuntimeException if unable to construct a valid request line.
44+
*/
45+
public function getRequestLine();
46+
47+
/**
48+
* Create a new instance with a specific request line.
49+
*
50+
* If the request needs a specific request line — for instance, to allow
51+
* specifying an absolute-form, authority-form, or asterisk-form
52+
* request-target — this method may be used to create an instance with
53+
* the specified request line, verbatim.
54+
*
55+
* This method MUST validate that the line is in the form:
56+
*
57+
* <code>
58+
* HTTP_METHOD REQUEST_TARGET HTTP/PROTOCOL_VERSION
59+
* </code>
60+
*
61+
* and raise an exception if not.
62+
*
63+
* This method MUST be implemented in such a way as to retain the
64+
* immutability of the message, and MUST return a new instance that has the
65+
* changed request line.
66+
*
67+
* @link http://tools.ietf.org/html/rfc7230#section-2.7 (for the various
68+
* request-target forms allowed in request messages)
69+
* @param mixed $requestLine
70+
* @return self
71+
* @throws \InvalidArgumentException for invalid request lines.
72+
*/
73+
public function withRequestLine($requestLine);
74+
2375
/**
2476
* Retrieves the HTTP method of the request.
2577
*
@@ -47,10 +99,10 @@ public function withMethod($method);
4799
/**
48100
* Retrieves the URI instance.
49101
*
50-
* This method MUST return a UriTargetInterface instance.
102+
* This method MUST return a UriInterface instance.
51103
*
52104
* @link http://tools.ietf.org/html/rfc3986#section-4.3
53-
* @return UriTargetInterface Returns a UriTargetInterface instance
105+
* @return UriInterface Returns a UriInterface instance
54106
* representing the URI of the request, if any.
55107
*/
56108
public function getUri();
@@ -60,11 +112,11 @@ public function getUri();
60112
*
61113
* This method MUST be implemented in such a way as to retain the
62114
* immutability of the message, and MUST return a new instance that has the
63-
* new UriTargetInterface instance.
115+
* new UriInterface instance.
64116
*
65117
* @link http://tools.ietf.org/html/rfc3986#section-4.3
66-
* @param UriTargetInterface $uri New request URI to use.
118+
* @param UriInterface $uri New request URI to use.
67119
* @return self
68120
*/
69-
public function withUri(UriTargetInterface $uri);
121+
public function withUri(UriInterface $uri);
70122
}

src/UriTargetInterface.php renamed to src/UriInterface.php

+8-70
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,23 @@
22
namespace Psr\Http\Message;
33

44
/**
5-
* Value object representing the request target, and typically a URI.
5+
* Value object representing a URI for use in HTTP requests.
6+
*
7+
* This interface is meant to represent only URIs for use with HTTP requests,
8+
* and is not intended as a general-purpose URI implementation.
69
*
710
* Instances of this interface are considered immutable; all methods that
811
* might change state MUST be implemented such that they retain the internal
912
* state of the current instance and return a new instance that contains the
1013
* changed state.
1114
*
12-
* Since this interface represents a request target per RFC 7230, the instance
13-
* MAY represent an absolute URI OR one of the request targets that are not
14-
* fully qualified URIs, including origin-form, authority-form, or
15-
* asterisk-form. As such, test methods exist for determining what request
16-
* target form is in use:
17-
*
18-
* - isAbsolute() tests if the target is in absolute-form (minimally scheme +
19-
* authority).
20-
* - isOrigin() tests if the target is in origin-form (path + optional query
21-
* string only).
22-
* - isAuthority() tests if the target contains the authority only.
23-
* - isAsterisk() tests if the entirety of the target is '*'.
24-
*
25-
* These target forms are included, as they are valid forms for use with an
26-
* HTTP request, and will appear without other URI segments available within
27-
* the request line. This interface models the target as it appears in the
28-
* incoming request line or as it will be emitted by a client.
29-
*
30-
* Typically, for all forms other than absolute-form, minimally the Host header
31-
* will be also be present in the request message. For server-side requests,
32-
* the scheme will typically be discoverable in the server parameters.
15+
* Typically the Host header will be also be present in the request message.
16+
* For server-side requests, the scheme will typically be discoverable in the
17+
* server parameters.
3318
*
3419
* @link http://tools.ietf.org/html/rfc3986 (the URI specification)
35-
* @link http://tools.ietf.org/html/rfc7230#section-2.7 (URIs as used in the HTTP specification)
3620
*/
37-
interface UriTargetInterface
21+
interface UriInterface
3822
{
3923
/**
4024
* Retrieve the URI scheme.
@@ -262,52 +246,6 @@ public function withQuery($query);
262246
*/
263247
public function withFragment($fragment);
264248

265-
/**
266-
* Indicate whether the URI is in origin-form.
267-
*
268-
* Origin-form is a URI that includes only the path, and optionally the
269-
* query string.
270-
*
271-
* @link http://tools.ietf.org/html/rfc7230#section-5.3.1
272-
* @return bool
273-
*/
274-
public function isOrigin();
275-
276-
/**
277-
* Indicate whether the URI is absolute.
278-
*
279-
* An absolute URI contains minimally a non-empty scheme and non-empty
280-
* authority.
281-
*
282-
* @see getAuthority()
283-
* @link http://tools.ietf.org/html/rfc7230#section-5.3.2
284-
* @return bool
285-
*/
286-
public function isAbsolute();
287-
288-
/**
289-
* Indicate whether the instance represents an authority-form request
290-
* target.
291-
*
292-
* An authority-form request-target contains ONLY the authority information.
293-
*
294-
* @see getAuthority()
295-
* @link http://tools.ietf.org/html/rfc7230#section-5.3.3
296-
* @return bool
297-
*/
298-
public function isAuthority();
299-
300-
/**
301-
* Indicate whether the instance represents an asterisk-form request
302-
* target.
303-
*
304-
* An asterisk-form request-target will contain ONLY the string "*".
305-
*
306-
* @link http://tools.ietf.org/html/rfc7230#section-5.3.4
307-
* @return bool
308-
*/
309-
public function isAsterisk();
310-
311249
/**
312250
* Return the string representation of the URI.
313251
*

0 commit comments

Comments
 (0)