Methods |
public
static
|
createURIString(
string|null $scheme = null,
?string $authority = null,
?string $path = null,
?string $query = null,
?string $fragment = null,
): string
Builds a representation of the string from the component parts.
Builds a representation of the string from the component parts.
Parameters
$scheme |
URI scheme. E.g., http, ftp
|
Returns
URI string with only passed parts. Maybe incomplete as a URI.
|
#
|
public
|
__construct(string|null $uri = null)
Constructor.
|
#
|
public
|
setSilent(bool $silent = true): URI
If $silent == true, then will not throw exceptions and will
attempt to continue gracefully.
If $silent == true, then will not throw exceptions and will
attempt to continue gracefully.
|
#
|
public
|
useRawQueryString(bool $raw = true): URI
If $raw == true, then will use parseStr() method
instead of native parse_str() function.
If $raw == true, then will use parseStr() method
instead of native parse_str() function.
|
#
|
public
|
setURI(?string $uri = null): URI
Sets and overwrites any current URI information.
Sets and overwrites any current URI information.
Throws
|
#
|
public
|
getScheme(): string
Retrieve the scheme component of the URI.
Retrieve the scheme component of the URI.
If no scheme is present, this method MUST return an empty string.
The value returned MUST be normalized to lowercase, per RFC 3986
Section 3.1.
The trailing ":" character is not part of the scheme and MUST NOT be
added.
Returns
|
#
|
public
|
getAuthority(bool $ignorePort = false): string
Retrieve the authority component of the URI.
Retrieve the authority component of the URI.
If no authority information is present, this method MUST return an empty
string.
The authority syntax of the URI is:
[user-info@]host[:port]
If the port component is not set or is the standard port for the current
scheme, it SHOULD NOT be included.
Returns
The URI authority, in "[user-info@]host[:port]" format.
|
#
|
public
|
getUserInfo(): string|null
Retrieve the user information component of the URI.
Retrieve the user information component of the URI.
If no user information is present, this method MUST return an empty
string.
If a user is present in the URI, this will return that value;
additionally, if the password is also present, it will be appended to the
user value, with a colon (":") separating the values.
NOTE that be default, the password, if available, will NOT be shown
as a security measure as discussed in RFC 3986, Section 7.5. If you know
the password is not a security issue, you can force it to be shown
with $this->showPassword();
The trailing "@" character is not part of the user information and MUST
NOT be added.
Returns
The URI user information, in "username[:password]" format.
|
#
|
public
|
showPassword(bool $val = true): URI
Temporarily sets the URI to show a password in userInfo. Will
reset itself after the first call to authority().
Temporarily sets the URI to show a password in userInfo. Will
reset itself after the first call to authority().
|
#
|
public
|
getHost(): string
Retrieve the host component of the URI.
Retrieve the host component of the URI.
If no host is present, this method MUST return an empty string.
The value returned MUST be normalized to lowercase, per RFC 3986
Section 3.2.2.
Returns
|
#
|
public
|
getPort(): int|null
Retrieve the port component of the URI.
Retrieve the port component of the URI.
If a port is present, and it is non-standard for the current scheme,
this method MUST return it as an integer. If the port is the standard port
used with the current scheme, this method SHOULD return null.
If no port is present, and no scheme is present, this method MUST return
a null value.
If no port is present, but a scheme is present, this method MAY return
the standard port for that scheme, but SHOULD return null.
Returns
|
#
|
public
|
getPath(): string
Retrieve the path component of the URI.
Retrieve the path component of the URI.
The path can either be empty or absolute (starting with a slash) or
rootless (not starting with a slash). Implementations MUST support all
three syntaxes.
Normally, the empty path "" and absolute path "/" are considered equal as
defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
do this normalization because in contexts with a trimmed base path, e.g.
the front controller, this difference becomes significant. It's the task
of the user to handle both "" and "/".
The value returned MUST be percent-encoded, but MUST NOT double-encode
any characters. To determine what characters to encode, please refer to
RFC 3986, Sections 2 and 3.3.
As an example, if the value should include a slash ("/") not intended as
delimiter between path segments, that value MUST be passed in encoded
form (e.g., "%2F") to the instance.
Returns
|
#
|
public
|
getQuery(array $options = []): string
Retrieve the query string
Retrieve the query string
|
#
|
public
|
getFragment(): string
Retrieve a URI fragment
|
#
|
public
|
getSegments(): array
Returns the segments of the path as an array.
Returns the segments of the path as an array.
|
#
|
public
|
getSegment(int $number, string $default = ''): string
Returns the value of a specific segment of the URI path.
Returns the value of a specific segment of the URI path.
Parameters
$number |
Segment number
|
$default |
Default value
|
Returns
The value of the segment. If no segment is found,
throws InvalidArgumentError
|
#
|
public
|
setSegment(int $number, mixed $value): $this
Set the value of a specific segment of the URI path.
Allows to set only existing segments or add new one.
Set the value of a specific segment of the URI path.
Allows to set only existing segments or add new one.
Parameters
|
#
|
public
|
getTotalSegments(): int
Returns the total number of segments.
Returns the total number of segments.
|
#
|
public
|
__toString(): string
Formats the URI as a string.
Formats the URI as a string.
Warning: For backwards-compatability this method
assumes URIs with the same host as baseURL should
be relative to the project's configuration.
This aspect of __toString() is deprecated and should be avoided.
|
#
|
public
|
setAuthority(string $str): $this
Parses the given string and saves the appropriate authority pieces.
Parses the given string and saves the appropriate authority pieces.
|
#
|
public
|
setScheme(string $str): $this
Sets the scheme for this URI.
Sets the scheme for this URI.
Because of the large number of valid schemes we cannot limit this
to only http or https.
|
#
|
public
|
setUserInfo(string $user, string $pass): $this
Sets the userInfo/Authority portion of the URI.
Sets the userInfo/Authority portion of the URI.
Parameters
$user |
The user's username
|
$pass |
The user's password
|
|
#
|
public
|
setHost(string $str): $this
Sets the host name to use.
Sets the host name to use.
|
#
|
public
|
setPort(int $port = null): $this
Sets the port portion of the URI.
Sets the port portion of the URI.
|
#
|
public
|
setPath(string $path): $this
Sets the path portion of the URI.
Sets the path portion of the URI.
|
#
|
public
|
setBaseURL(string $baseURL): void
Sets the current baseURL.
Sets the current baseURL.
|
#
|
public
|
getBaseURL(): string
Returns the current baseURL.
Returns the current baseURL.
|
#
|
public
|
refreshPath(): $this
Sets the path portion of the URI based on segments.
Sets the path portion of the URI based on segments.
|
#
|
public
|
setQuery(string $query): $this
Sets the query portion of the URI, while attempting
to clean the various parts of the query keys and values.
Sets the query portion of the URI, while attempting
to clean the various parts of the query keys and values.
|
#
|
public
|
setQueryArray(array $query): URI
A convenience method to pass an array of items in as the Query
portion of the URI.
A convenience method to pass an array of items in as the Query
portion of the URI.
|
#
|
public
|
addQuery(string $key, mixed $value = null): $this
Adds a single new element to the query vars.
Adds a single new element to the query vars.
|
#
|
public
|
stripQuery(string ...$params): $this
Removes one or more query vars from the URI.
Removes one or more query vars from the URI.
|
#
|
public
|
keepQuery(string ...$params): $this
Filters the query variables so that only the keys passed in
are kept. The rest are removed from the object.
Filters the query variables so that only the keys passed in
are kept. The rest are removed from the object.
|
#
|
public
|
setFragment(string $string): $this
Sets the fragment portion of the URI.
Sets the fragment portion of the URI.
|
#
|
protected
|
filterPath(?string $path = null): string
Encodes any dangerous characters, and removes dot segments.
While dot segments have valid uses according to the spec,…
Encodes any dangerous characters, and removes dot segments.
While dot segments have valid uses according to the spec,
this URI class does not allow them.
|
#
|
protected
|
applyParts(array $parts)
Saves our parts from a parse_url call.
Saves our parts from a parse_url call.
|
#
|
public
|
resolveRelativeURI(string $uri): URI
Combines one URI string with this one based on the rules set out in
RFC 3986 Section 2
Combines one URI string with this one based on the rules set out in
RFC 3986 Section 2
|
#
|
protected
|
mergePaths(self $base, self $reference): string
Given 2 paths, will merge them according to rules set out in RFC 2986,
Section 5.2
Given 2 paths, will merge them according to rules set out in RFC 2986,
Section 5.2
|
#
|
protected
|
parseStr(string $query): array
This is equivalent to the native PHP parse_str() function.
This version allows the dot to be used as a key of the query…
This is equivalent to the native PHP parse_str() function.
This version allows the dot to be used as a key of the query string.
|
#
|