Since: 8.5

final class Uri (View source)

Methods

static Uri|null
parse(string $uri, Uri|null $baseUrl = null)

Parse a URI

__construct(string $uri, Uri|null $baseUrl = null)

No description

string|null
getScheme()

Retrieve the normalized scheme component

string|null
getRawScheme()

Retrieve the raw scheme component

Uri
withScheme(string|null $scheme)

No description

string|null
getUserInfo()

Retrieve the normalized userinfo component

string|null
getRawUserInfo()

Retrieve the raw userinfo component

Uri
withUserInfo(string|null $userinfo)

No description

string|null
getUsername()

Retrieve the normalized username

string|null
getRawUsername()

Retrieve the raw username

string|null
getPassword()

Retrieve the normalized password

string|null
getRawPassword()

Retrieve the raw password

string|null
getHost()

Retrieve the normalized host component

string|null
getRawHost()

Retrieve the raw host component

Uri
withHost(string|null $host)

No description

int|null
getPort()

Retrieve the normalized port component

Uri
withPort(int|null $port)

No description

string
getPath()

Retrieve the normalized path component

string
getRawPath()

Retrieve the raw path component

Uri
withPath(string $path)

No description

string|null
getQuery()

Retrieve the normalized query component

string|null
getRawQuery()

Retrieve the raw query component

Uri
withQuery(string|null $query)

No description

string|null
getFragment()

Retrieve the normalized fragment component

string|null
getRawFragment()

Retrieve the raw fragment component

Uri
withFragment(string|null $fragment)

No description

bool
equals(Uri $uri, UriComparisonMode $comparisonMode = \Uri\UriComparisonMode::ExcludeFragment)

Check if two URIs are equivalent

string
toString()

Recompose the normalized URI

string
toRawString()

Recompose the raw URI

Uri
resolve(string $uri)

No description

array
__serialize()

No description

void
__unserialize(array $data)

No description

array
__debugInfo()

Return the internal state of the URI

UriHostType|null
getHostType()

No description

UriType|null
getUriType()

No description

Details

static Uri|null parse(string $uri, Uri|null $baseUrl = null)

Parse a URI

Parses a URI.

Parameters

string $uri

URI to parse.

Uri|null $baseUrl

When a string is passed, uri is applied on baseUrl, if uri is a relative reference. If either null is passed, or uri is a not a relative reference, then baseUrl doesn't have any effect.

Return Value

Uri|null

Returns a Uri\Rfc3986\Uri instance on success, or null on failure.

__construct(string $uri, Uri|null $baseUrl = null)

No description

Parameters

string $uri
Uri|null $baseUrl

Exceptions

InvalidUriException

string|null getScheme()

Retrieve the normalized scheme component

Retrieves the normalized scheme component.

Return Value

string|null

Returns the normalized scheme component as a string if the scheme component exists, null is returned otherwise.

string|null getRawScheme()

Retrieve the raw scheme component

Retrieves the raw (non-normalized) scheme component.

Return Value

string|null

Returns the raw scheme component as a string if the scheme component exists, null is returned otherwise.

Uri withScheme(string|null $scheme)

No description

Parameters

string|null $scheme

Return Value

Uri

Exceptions

InvalidUriException

string|null getUserInfo()

Retrieve the normalized userinfo component

Retrieves the normalized userinfo component.

Return Value

string|null

Returns the normalized userinfo component as a string if the userinfo component exists, null is returned otherwise.

string|null getRawUserInfo()

Retrieve the raw userinfo component

Retrieves the raw (non-normalized) userinfo component.

Return Value

string|null

Returns the raw userinfo component as a string if the userinfo component exists, null is returned otherwise.

Uri withUserInfo(string|null $userinfo)

No description

Parameters

string|null $userinfo

Return Value

Uri

Exceptions

InvalidUriException

string|null getUsername()

Retrieve the normalized username

Retrieves the normalized username part (the text before the first : character) from the userinfo component.

Return Value

string|null

Returns the normalized username as a string if the userinfo component exists, null is returned otherwise.

string|null getRawUsername()

Retrieve the raw username

Retrieves the raw (non-normalized) username part (the text before the first : character) from userinfo component.

Return Value

string|null

Returns the raw (non-normalized) username as a string if the userinfo component exists, null is returned otherwise.

string|null getPassword()

Retrieve the normalized password

Retrieves the normalized password part (the text after the first : character) from the userinfo component.

Return Value

string|null

Returns the normalized password as a string if the userinfo component contains a : character. An empty string is returned when the userinfo component doesn't contain a : character. null is returned when the userinfo component doesn't exist.

string|null getRawPassword()

Retrieve the raw password

Retrieves the raw (non-normalized) password part (the text after the first : character) from the userinfo component.

Return Value

string|null

Returns the raw (non-normalized) password as a string if the userinfo component contains a : character. An empty string is returned when the userinfo component doesn't contain a : character. null is returned when the userinfo component doesn't exist.

string|null getHost()

Retrieve the normalized host component

Retrieves the normalized host component.

Return Value

string|null

Returns the normalized host component as a string if the host component exists, null is returned otherwise.

string|null getRawHost()

Retrieve the raw host component

Retrieves the raw (non-normalized) host component.

Return Value

string|null

Returns the raw host component as a string if the host component exists, null is returned otherwise.

Uri withHost(string|null $host)

No description

Parameters

string|null $host

Return Value

Uri

Exceptions

InvalidUriException

int|null getPort()

Retrieve the normalized port component

Retrieves the normalized port component.

Return Value

int|null

Returns the normalized port component as an integer if the port component exists, null is returned otherwise.

Uri withPort(int|null $port)

No description

Parameters

int|null $port

Return Value

Uri

Exceptions

InvalidUriException

string getPath()

Retrieve the normalized path component

Retrieves the normalized path component.

Return Value

string

Returns the normalized path component as a string.

string getRawPath()

Retrieve the raw path component

Retrieves the raw (non-normalized) path component.

Return Value

string

Returns the raw path component as a string.

Uri withPath(string $path)

No description

Parameters

string $path

Return Value

Uri

Exceptions

InvalidUriException

string|null getQuery()

Retrieve the normalized query component

Retrieves the normalized query component.

Return Value

string|null

Returns the normalized query component as a string if the query component exists, null is returned otherwise.

string|null getRawQuery()

Retrieve the raw query component

Retrieves the raw (non-normalized) query component.

Return Value

string|null

Returns the raw query component as a string if the query component exists, null is returned otherwise.

Uri withQuery(string|null $query)

No description

Parameters

string|null $query

Return Value

Uri

Exceptions

InvalidUriException

string|null getFragment()

Retrieve the normalized fragment component

Retrieves the normalized fragment component.

Return Value

string|null

Returns the normalized fragment component as a string if the fragment component exists, null is returned otherwise.

string|null getRawFragment()

Retrieve the raw fragment component

Retrieves the raw (non-normalized) fragment component.

Return Value

string|null

Returns the raw fragment component as a string if the fragment component exists, null is returned otherwise.

Uri withFragment(string|null $fragment)

No description

Parameters

string|null $fragment

Return Value

Uri

Exceptions

InvalidUriException

bool equals(Uri $uri, UriComparisonMode $comparisonMode = \Uri\UriComparisonMode::ExcludeFragment)

Check if two URIs are equivalent

Checks if two URIs are equivalent.

Parameters

Uri $uri

URI to compare the current URI against.

UriComparisonMode $comparisonMode

Whether the fragment component is taken into account of the comparison (Uri\UriComparisonMode::IncludeFragment) or not (Uri\UriComparisonMode::ExcludeFragment). By default, the fragment is excluded.

Return Value

bool

Returns true if the two URIs are equivalent, or false otherwise.

string toString()

Recompose the normalized URI

Recomposes the normalized URI to a string.

Return Value

string

Returns the recomposed normalized URI as a string.

string toRawString()

Recompose the raw URI

Recomposes the raw (non-normalized) URI to a string.

Return Value

string

Returns the recomposed raw (non-normalized) URI as a string.

Uri resolve(string $uri)

No description

Parameters

string $uri

Return Value

Uri

Exceptions

InvalidUriException

array __serialize()

No description

Return Value

array

Exceptions

Exception

void __unserialize(array $data)

No description

Parameters

array $data

Return Value

void

Exceptions

Exception

array __debugInfo()

Return the internal state of the URI

Returns the internal state of the URI.

Return Value

array

Returns the internal state of the URI as an array.

UriHostType|null getHostType()

Since: 8.6

No description

Return Value

UriHostType|null

UriType|null getUriType()

Since: 8.6

No description

Return Value

UriType|null