Skip to content

Commit 754d423

Browse files
committed
Normalized to follow original URI proposal
See https://github.com/php-fig/fig-standards/blob/3486dc9184e9a099118389cd3e032295852d011e/proposed/uri.md I examined this proposal, as well as looked in depth at RFC's 3986 and 7230 to see what overlap we had and/or needed. The interface in its current form now is mostly compatible with the original proposal. It differs in the following ways: - Since this proposal targets HTTP requests specifically, I did not separate URI vs Hierarchical URI vs Opaque. - This proposal combines aspects of the originally proposed UriInterface and the HierarchicalUriInterface, particularly around the various getters. - I have omitted the `to(Encoded|Decoded)String()` methods, as they are essentially irrelevant for HTTP messages (requests will always want decoded URIs). - I have omitted `getQueryAsArray()` as I'm not 100% sold on their efficacy for HTTP messages, particularly as ServerRequest already defines `getQueryParams()` - I omitted `getHierarchicalPart()`, as I could not find a use case within the domain of HTTP messages. - I omitted `normalize()`, `resolve()`, and `relativize()` as I did not have immediate use cases for them with regards to HTTP messages. They may be useful for HTTP clients, however. - I modified `getAuthority()` to return the authority segment of a URI. - I added `getUserInfo()` to perform what `getAuthority()` was doing previously, and renamed `withAuthority()` to `withUserInfo()`. With the changes made, an implementation that bridges the original interfaces and those in this proposal can be made that are 100% compatible.
1 parent 77ba53d commit 754d423

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/UriInterface.php

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,37 @@ public function getScheme();
2727
/**
2828
* Retrieve the authority portion of the URI.
2929
*
30-
* The authority portion of a URI when present, can consist of a username,
31-
* and optionally the password/credentials for that user. The return MUST
32-
* be a string, in the format of "username[:password]", where the colon and
33-
* password are only present if they were provided. (Brackets MUST NOT be
34-
* present; they are used here to indicate that those items are optional)
30+
* The authority portion of the URI is:
3531
*
36-
* The string returned MUST strip off the trailing "@" delimiter if
37-
* present.
32+
* <pre>
33+
* [user-info@]host[:port]
34+
* </pre>
35+
*
36+
* If the port component is not set or is the standard port for the current
37+
* scheme, it SHOULD NOT be included.
3838
*
3939
* This method MUST return an empty string if no authority information is
4040
* present.
4141
*
42-
* @return string Authority portion of the URI, in "username[:password]"
42+
* @return string Authority portion of the URI, in "[user-info@]host[:port]"
4343
* format.
4444
*/
4545
public function getAuthority();
4646

47+
/**
48+
* Retrieve the user information portion of the URI, if present.
49+
*
50+
* If a user is present in the URI, this will return that value;
51+
* additionally, if the password is also present, it will be appended to the
52+
* user value, with a colon (":") separating the values.
53+
*
54+
* Implementations MUST NOT return the "@" suffix when returning this value.
55+
*
56+
* @return string User information portion of the URI, if present, in
57+
* "username[:password]" format.
58+
*/
59+
public function getUserInfo();
60+
4761
/**
4862
* Retrieve the host segment of the URI.
4963
*
@@ -119,20 +133,20 @@ public function getFragment();
119133
public function withScheme($scheme);
120134

121135
/**
122-
* Create a new instance with the specified authority information.
136+
* Create a new instance with the specified user information.
123137
*
124138
* This method MUST retain the state of the current instance, and return
125-
* a new instance that contains the specified authority information.
139+
* a new instance that contains the specified user information.
126140
*
127-
* Password is optional, but the authority information MUST include the
141+
* Password is optional, but the user information MUST include the
128142
* user.
129143
*
130144
* @param string $user User name to use for authority.
131145
* @param null|string $password Password associated with $user.
132-
* @return UriInterface A new instance with the specified authority
146+
* @return UriInterface A new instance with the specified user
133147
* information.
134148
*/
135-
public function withAuthority($user, $password = null);
149+
public function withUserInfo($user, $password = null);
136150

137151
/**
138152
* Create a new instance with the specified host.
@@ -208,37 +222,41 @@ public function withFragment($fragment);
208222
* Origin-form is a URI that includes only the path and optionally the
209223
* query string.
210224
*
225+
* @see http://tools.ietf.org/html/rfc7230#section-5.3.1
211226
* @return bool
212227
*/
213-
public function isOriginForm();
228+
public function isOrigin();
214229

215230
/**
216231
* Indicate whether the URI is absolute.
217232
*
218233
* An absolute URI contains minimally the scheme and host.
219234
*
235+
* @see http://tools.ietf.org/html/rfc7230#section-5.3.2
220236
* @return bool
221237
*/
222-
public function isAbsoluteForm();
238+
public function isAbsolute();
223239

224240
/**
225241
* Indicate whether the URI is in authority form.
226242
*
227243
* An authority-form URI is an absolute URI that also contains authority
228244
* information.
229245
*
246+
* @see http://tools.ietf.org/html/rfc7230#section-5.3.3
230247
* @return bool
231248
*/
232-
public function isAuthorityForm();
249+
public function isAuthority();
233250

234251
/**
235-
* Indicate whether the URI is an asterix form.
252+
* Indicate whether the URI is an asterisk-form.
236253
*
237-
* An asterix form URI will have "*" as the path, and no other URI parts.
254+
* An asterisk form URI will have "*" as the path, and no other URI parts.
238255
*
256+
* @see http://tools.ietf.org/html/rfc7230#section-5.3.4
239257
* @return bool
240258
*/
241-
public function isAsterixForm();
259+
public function isAsterisk();
242260

243261
/**
244262
* Return the string representation of the URI.

0 commit comments

Comments
 (0)