Uri
class Uri implements UriInterface (View source)
Immutable value object that represents a RFC3986 compliant URI.
Traits
Methods
Returns the scheme component of the URI.
Returns the user information component of the URI.
Returns the host component of the URI.
Returns the top level domain from the host component.
Returns the path component of the URI.
Returns the decoded path segments from the path component.
Returns the file extension for the last segment in the path.
Returns the query string of the URI.
Returns the decoded parameters parsed from the query component.
Returns a URI instance with path constructed from given path segments.
Returns a URI instance with the query constructed from the given parameters.
Creates a new instance of Uri.
Returns the authority component of the URI.
Returns the port component of the URI.
Returns the fragment component of the URI.
Returns a URI instance with the specified scheme.
Returns a URI instance with the specified user information.
Returns a URI instance with the specified URI fragment.
Returns the string representation of the URI.
Details
at line 74
string
getScheme()
Returns the scheme component of the URI.
Note that the returned value will always be normalized to lowercase, as per RFC 3986 Section 3.1. If no scheme has been provided, an empty string will be returned instead.
in ExtendedUriTrait at line 42
int|null
getStandardPort()
Returns the standard port for the current scheme.
The known ports are:
- ftp : 21
- http : 80
- https : 443
at line 114
string
getUserInfo()
Returns the user information component of the URI.
The user information component contains the username and password in the URI separated by a colon. If no username has been provided, an empty string will be returned instead. If no password has been provided, the returned value will only contain the username without the delimiting colon.
in ExtendedUriTrait at line 63
string
getUsername()
Returns the decoded username from the URI.
in ExtendedUriTrait at line 75
string
getPassword()
Returns the decoded password from the URI.
at line 129
string
getHost()
Returns the host component of the URI.
Note that the returned value will always be normalized to lowercase, as per RFC 3986 Section 3.2.2. If no host has been provided, an empty string will be returned instead.
in ExtendedUriTrait at line 92
string|null
getIpAddress()
Returns the IP address from the host component.
in ExtendedUriTrait at line 117
string
getTopLevelDomain()
Returns the top level domain from the host component.
Note that if the host component represents an IP address, an empty string will be returned instead. Additionally, if the host component ends in a period, the section prior that period will be returned instead. If no period is present in the host component, the entire host component will be returned.
at line 158
string
getPath()
Returns the path component of the URI.
in ExtendedUriTrait at line 144
string[]
getPathSegments()
Returns the decoded path segments from the path component.
in ExtendedUriTrait at line 156
string
getPathExtension()
Returns the file extension for the last segment in the path.
at line 168
string
getQuery()
Returns the query string of the URI.
in ExtendedUriTrait at line 179
array
getQueryParameters()
Returns the decoded parameters parsed from the query component.
at line 294
Uri
withPath(string $path)
Returns a URI instance with the specified path.
The provided path may or may not begin with a forward slash. The path will be automatically normalized with the appropriate number of slashes once the string is generated from the Uri instance. An empty string can be used to remove the path. The path may also contain percent encoded characters as these characters will not be double encoded.
in ExtendedUriTrait at line 204
ExtendedUriTrait
withPathSegments(array $segments)
Returns a URI instance with path constructed from given path segments.
Note that all the segments are assumed to be decoded. Thus any percent encoded characters in the segments will be double encoded. Due to aggressive encoding, this method will encode even the forward slashes in the provided segments.
at line 309
Uri
withQuery(string $query)
Returns a URI instance with the specified query string.
An empty string can be used to remove the query string. The provided value may contain both encoded and unencoded characters. Encoded characters will not be double encoded.
in ExtendedUriTrait at line 230
ExtendedUriTrait
withQueryParameters(array $parameters)
Returns a URI instance with the query constructed from the given parameters.
The provided associative array will be used to construct the query string. Even characters such as the ampersand and equal sign will be encoded in resulting string. Note the any percent encoded characters will be double encoded, since this method assumes that all the values are unencoded.
at line 44
__construct(string $uri = '', int $mode = UriParser::MODE_RFC3986)
Creates a new instance of Uri.
at line 94
string
getAuthority()
Returns the authority component of the URI.
If no authority information has been provided, an empty string will be returned instead. Note that the host component in the authority component will always be normalized to lowercase as per RFC 3986 Section 3.2.2.
Also note that even if a port has been provided, but it is the standard port for the current scheme, the port will not be included in the returned value.
The format of the returned value is [user-info@]host[:port]
at line 144
int|null
getPort()
Returns the port component of the URI.
If no port has been provided, this method will return a null instead. Note that this method will also return a null, if the provided port is the standard port for the current scheme.
at line 178
string
getFragment()
Returns the fragment component of the URI.
at line 196
Uri
withScheme(string $scheme)
Returns a URI instance with the specified scheme.
This method allows all different kinds of schemes. Note, however, that the different components are only validated based on the generic URI syntax. No additional validation is performed based on the scheme. An empty string can be used to remove the scheme. Note that the provided scheme will be normalized to lowercase.
at line 221
Uri
withUserInfo(string $user, string|null $password = null)
Returns a URI instance with the specified user information.
Note that the password is optional, but unless an username is provided, the password will be ignored. Note that this method assumes that neither the username nor the password contains encoded characters. Thus, all encoded characters will be double encoded, if present. An empty username can be used to remove the user information.
at line 247
Uri
withHost(string $host)
Returns a URI instance with the specified host.
An empty host can be used to remove the host. Note that since host names are treated in a case insensitive manner, the host will be normalized to lowercase. This method does not support international domain names and hosts with non ascii characters are considered invalid.
at line 269
Uri
withPort(int|null $port)
Returns a URI instance with the specified port.
A null value can be used to remove the port number. Note that if an invalid port number is provided (a number less than 0 or more than 65535), an exception will be thrown.
at line 324
Uri
withFragment(string $fragment)
Returns a URI instance with the specified URI fragment.
An empty string can be used to remove the fragment. The provided value may contain both encoded and unencoded characters. Encoded characters will not be double encoded.
at line 391
string
__toString()
Returns the string representation of the URI.
The resulting URI will be composed of the provided components. All components that have not been provided will be omitted from the generated URI. The provided path will be normalized based on whether the authority is included in the URI or not.