class PsrUri extends AbstractUri implements UriInterface (View source)

The PsrUri class.

Constants

SCHEME_HTTP

SCHEME_HTTPS

CHAR_SUB_DELIMS

Sub-delimiters used in query strings and fragments.

CHAR_UNRESERVED

Unreserved characters used in paths, query strings, and fragments.

Methods

__construct(string $uri = '')

Constructor.

string
__toString()

Magic method to get the string representation of the URI object.

string
toString(array $parts = array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'))

Returns full uri string.

boolean
hasVar(string $name)

Checks if variable exists.

array
getVar(string $name, string $default = null)

Returns a query variable by name.

string
getQuery(boolean $toArray = false)

Returns flat query string.

string
getScheme()

Get URI scheme (protocol) ie. http, https, ftp, etc.

string
getUser()

Get URI username Returns the username, or null if no username was specified.

string
getPass()

Get URI password Returns the password, or null if no password was specified.

string
getUserInfo()

Retrieve the user information component of the URI.

string
getHost()

Get URI host Returns the hostname/ip or null if no hostname/ip was specified.

integer
getPort()

Get URI port Returns the port number, or null if no port was specified.

string
getPath()

Gets the URI path string.

string
getFragment()

Get the URI archor string Everything after the "#".

boolean
isSSL()

Checks whether the current URI is using HTTPS.

string
getOriginal()

getUri

string
getAuthority()

Retrieve the authority component of the URI.

withScheme(string $scheme)

Return an instance with the specified scheme.

withUserInfo(string $user, string $password = null)

Return an instance with the specified user information.

withHost(string $host)

Return an instance with the specified host.

withPort(int $port)

Return an instance with the specified port.

withPath(string $path)

Return an instance with the specified path.

withQuery(string|array $query)

Return an instance with the specified query string.

withFragment(string $fragment)

Return an instance with the specified URI fragment.

Details

at line line 52
__construct(string $uri = '')

Constructor.

You can pass a URI string to the constructor to initialise a specific URI.

Parameters

string $uri The optional URI string

string __toString()

Magic method to get the string representation of the URI object.

Return Value

string

string toString(array $parts = array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'))

Returns full uri string.

Parameters

array $parts An array specifying the parts to render.

Return Value

string The rendered URI string.

boolean hasVar(string $name)

Checks if variable exists.

Parameters

string $name Name of the query variable to check.

Return Value

boolean True if the variable exists.

array getVar(string $name, string $default = null)

Returns a query variable by name.

Parameters

string $name Name of the query variable to get.
string $default Default value to return if the variable is not set.

Return Value

array Query variables.

string getQuery(boolean $toArray = false)

Returns flat query string.

Parameters

boolean $toArray True to return the query as a key => value pair array.

Return Value

string Query string.

string getScheme()

Get URI scheme (protocol) ie. http, https, ftp, etc.

..

Return Value

string The URI scheme.

string getUser()

Get URI username Returns the username, or null if no username was specified.

Return Value

string The URI username.

string getPass()

Get URI password Returns the password, or null if no password was specified.

Return Value

string The URI password.

string getUserInfo()

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.

The trailing "@" character is not part of the user information and MUST NOT be added.

Return Value

string The URI user information, in "username[:password]" format.

string getHost()

Get URI host Returns the hostname/ip or null if no hostname/ip was specified.

Return Value

string The URI host.

integer getPort()

Get URI port Returns the port number, or null if no port was specified.

Return Value

integer The URI port number.

string getPath()

Gets the URI path string.

Return Value

string The URI path string.

string getFragment()

Get the URI archor string Everything after the "#".

Return Value

string The URI anchor string.

boolean isSSL()

Checks whether the current URI is using HTTPS.

Return Value

boolean True if using SSL via HTTPS.

string getOriginal()

getUri

Return Value

string

at line line 81
string getAuthority()

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.

Return Value

string The URI authority, in "[user-info@]host[:port]" format.

See also

https://tools.ietf.org/html/rfc3986#section-3.2

at line line 122
PsrUri withScheme(string $scheme)

Return an instance with the specified scheme.

This method MUST retain the state of the current instance, and return an instance that contains the specified scheme.

Implementations MUST support the schemes "http" and "https" case insensitively, and MAY accommodate other schemes if required.

An empty scheme is equivalent to removing the scheme.

Parameters

string $scheme The scheme to use with the new instance.

Return Value

PsrUri A new instance with the specified scheme.

Exceptions

InvalidArgumentException for invalid or unsupported schemes.

at line line 152
PsrUri withUserInfo(string $user, string $password = null)

Return an instance with the specified user information.

This method MUST retain the state of the current instance, and return an instance that contains the specified user information.

Password is optional, but the user information MUST include the user; an empty string for the user is equivalent to removing user information.

Parameters

string $user The user name to use for authority.
string $password The password associated with $user.

Return Value

PsrUri A new instance with the specified user information.

at line line 185
PsrUri withHost(string $host)

Return an instance with the specified host.

This method MUST retain the state of the current instance, and return an instance that contains the specified host.

An empty host value is equivalent to removing the host.

Parameters

string $host The hostname to use with the new instance.

Return Value

PsrUri A new instance with the specified host.

Exceptions

InvalidArgumentException for invalid hostnames.

at line line 216
PsrUri withPort(int $port)

Return an instance with the specified port.

This method MUST retain the state of the current instance, and return an instance that contains the specified port.

Implementations MUST raise an exception for ports outside the established TCP and UDP port ranges.

A null value provided for the port is equivalent to removing the port information.

Parameters

int $port The port to use with the new instance; a null value removes the port information.

Return Value

PsrUri A new instance with the specified port.

Exceptions

InvalidArgumentException for invalid ports.

at line line 262
PsrUri withPath(string $path)

Return an instance with the specified path.

This method MUST retain the state of the current instance, and return an instance that contains the specified path.

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.

If the path is intended to be domain-relative rather than path relative then it must begin with a slash ("/"). Paths not starting with a slash ("/") are assumed to be relative to some base path known to the application or consumer.

Users can provide both encoded and decoded path characters. Implementations ensure the correct encoding as outlined in getPath().

Parameters

string $path The path to use with the new instance.

Return Value

PsrUri A new instance with the specified path.

Exceptions

InvalidArgumentException for invalid paths.

at line line 301
PsrUri withQuery(string|array $query)

Return an instance with the specified query string.

This method MUST retain the state of the current instance, and return an instance that contains the specified query string.

Users can provide both encoded and decoded query characters. Implementations ensure the correct encoding as outlined in getQuery().

An empty query string value is equivalent to removing the query string.

Parameters

string|array $query The query string to use with the new instance.

Return Value

PsrUri A new instance with the specified query string.

Exceptions

InvalidArgumentException for invalid query strings.

at line line 332
PsrUri withFragment(string $fragment)

Return an instance with the specified URI fragment.

This method MUST retain the state of the current instance, and return an instance that contains the specified URI fragment.

Users can provide both encoded and decoded fragment characters. Implementations ensure the correct encoding as outlined in getFragment().

An empty fragment value is equivalent to removing the fragment.

Parameters

string $fragment The fragment to use with the new instance.

Return Value

PsrUri A new instance with the specified fragment.