trait ExtendedUriTrait (View source)

Provides convenience methods for accessing the standard URI interface.

ExtendedUriTrait provides additional methods for common use cases that build on top the standard URI interface. Note that due to RFC 3986 compliance, the methods do not treat the plus sign as a space character.

Methods

string
getScheme()

Returns the scheme component of the URI.

int|null
getStandardPort()

Returns the standard port for the current scheme.

string
getUserInfo()

Returns the user information component of the URI.

string
getUsername()

Returns the decoded username from the URI.

string
getPassword()

Returns the decoded password from the URI.

string
getHost()

Returns the host component of the URI.

string|null
getIpAddress()

Returns the IP address from the host component.

string
getTopLevelDomain()

Returns the top level domain from the host component.

string
getPath()

Returns the path component of the URI.

string[]
getPathSegments()

Returns the decoded path segments from the path component.

string
getPathExtension()

Returns the file extension for the last segment in the path.

string
getQuery()

Returns the query string of the URI.

array
getQueryParameters()

Returns the decoded parameters parsed from the query component.

withPath(string $path)

Returns a URI instance with the specified path.

withPathSegments(array $segments)

Returns a URI instance with path constructed from given path segments.

withQuery(string $query)

Returns a URI instance with the specified query string.

withQueryParameters(array $parameters)

Returns a URI instance with the query constructed from the given parameters.

Details

abstract string getScheme()

Returns the scheme component of the URI.

Return Value

string The URI scheme

int|null getStandardPort()

Returns the standard port for the current scheme.

The known ports are:

  • ftp : 21
  • http : 80
  • https : 443

Return Value

int|null The standard port for the current scheme or null if not known

abstract string getUserInfo()

Returns the user information component of the URI.

Return Value

string The URI user information

string getUsername()

Returns the decoded username from the URI.

Return Value

string The decoded username

string getPassword()

Returns the decoded password from the URI.

Return Value

string The decoded password

abstract string getHost()

Returns the host component of the URI.

Return Value

string The URI host

string|null getIpAddress()

Returns the IP address from the host component.

Return Value

string|null IP address from the host or null if the host is not an IP address

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.

Return Value

string The top level domain or an empty string, if no TLD is present

abstract string getPath()

Returns the path component of the URI.

Return Value

string The URI path

string[] getPathSegments()

Returns the decoded path segments from the path component.

Return Value

string[] The decoded non empty path segments

string getPathExtension()

Returns the file extension for the last segment in the path.

Return Value

string The file extension from the last non empty segment

abstract string getQuery()

Returns the query string of the URI.

Return Value

string The URI query string

array getQueryParameters()

Returns the decoded parameters parsed from the query component.

Return Value

array The decoded parameters parsed from the query

abstract ExtendedUriTrait withPath(string $path)

Returns a URI instance with the specified path.

Parameters

string $path The path to use with the new instance

Return Value

ExtendedUriTrait A new instance with the specified path

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.

Parameters

array $segments Path segments for the new path

Return Value

ExtendedUriTrait A new instance with the specified path

abstract ExtendedUriTrait withQuery(string $query)

Returns a URI instance with the specified query string.

Parameters

string $query The query string to use with the new instance

Return Value

ExtendedUriTrait A new instance with the specified query string

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.

Parameters

array $parameters Parameters for the query

Return Value

ExtendedUriTrait A new instance with the specified query string