Since: 8.5

final class Url (View source)

Methods

static Url|null
parse(string $uri, Url|null $baseUrl = null, array $errors = null)

Parse a URL

__construct(string $uri, Url|null $baseUrl = null, array $softErrors = null)

Construct the Url object

string
getScheme()

Retrieve the scheme component

Url
withScheme(string $scheme)

Modify the scheme component

string|null
getUsername()

Retrieve the username component

Url
withUsername(string|null $username)

Modify the username component

string|null
getPassword()

Retrieve the password component

Url
withPassword(string|null $password)

Modify the password component

string|null
getAsciiHost()

Retrieve the host component as an ASCII string

string|null
getUnicodeHost()

Retrieve the host component as an Unicode string

Url
withHost(string|null $host)

Modify the host component

int|null
getPort()

Retrieve the port component

Url
withPort(int|null $port)

Modify the port component

string
getPath()

Retrieve the path component

Url
withPath(string $path)

Modify the path component

string|null
getQuery()

Retrieve the query component

Url
withQuery(string|null $query)

Modify the query component

string|null
getFragment()

Retrieve the fragment component

Url
withFragment(string|null $fragment)

Modify the fragment component

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

Check if two URLs are equivalent

string
toAsciiString()

Recompose the URL as an ASCII string

string
toUnicodeString()

Recompose the URL as a Unicode string

Url
resolve(string $uri, array $softErrors = null)

Resolve a URL with the current object as the base URL

array
__serialize()

Serialize the Url object

void
__unserialize(array $data)

Deserialize the data parameter into a Url object

array
__debugInfo()

Return the internal state of the URL

UrlHostType|null
getHostType()

No description

bool
isSpecialScheme()

No description

Details

static Url|null parse(string $uri, Url|null $baseUrl = null, array $errors = null)

Parse a URL

Parses a URL.

Parameters

string $uri

A valid URL string to parse (e.g. /foo or (e.g. https://example.com/foo).

Url|null $baseUrl

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

array $errors

An array to pass a list of Uri\WhatWg\UrlValidationError instances by reference to provide extended information about the errors triggered during parsing.

Return Value

Url|null

__construct(string $uri, Url|null $baseUrl = null, array $softErrors = null)

Construct the Url object

Constructs the Uri\Rfc3986\Uri object.

Parameters

string $uri

A valid URL string to parse (e.g. /foo or (e.g. https://example.com/foo).

Url|null $baseUrl

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

array $softErrors

An array to pass a list of Uri\WhatWg\UrlValidationError instances by reference to provide extended information about the errors triggered during parsing.

Exceptions

InvalidUrlException

string getScheme()

Retrieve the scheme component

Retrieves the scheme component.

Return Value

string

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

Url withScheme(string $scheme)

Modify the scheme component

Creates a new URL and modifies its scheme component.

Parameters

string $scheme

Return Value

Url

Exceptions

InvalidUrlException

string|null getUsername()

Retrieve the username component

Retrieves the username component.

Return Value

string|null

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

Url withUsername(string|null $username)

Modify the username component

Creates a new URL and modifies its username component.

Parameters

string|null $username

Return Value

Url

Exceptions

InvalidUrlException

string|null getPassword()

Retrieve the password component

Retrieves the password component.

Return Value

string|null

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

Url withPassword(string|null $password)

Modify the password component

Creates a new URL and modifies its password component.

Parameters

string|null $password

Return Value

Url

Exceptions

InvalidUrlException

string|null getAsciiHost()

Retrieve the host component as an ASCII string

Retrieves the host component as a string using punycode transcription instead of Unicode characters.

Return Value

string|null

Returns the host component as an ASCII string if the host component exists, null is returned otherwise.

string|null getUnicodeHost()

Retrieve the host component as an Unicode string

Retrieves the host component as a string, which may contain Unicode characters.

Return Value

string|null

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

Url withHost(string|null $host)

Modify the host component

Creates a new URL and modifies its host component.

Parameters

string|null $host

Return Value

Url

Exceptions

InvalidUrlException

int|null getPort()

Retrieve the port component

Retrieves the port component.

Return Value

int|null

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

Url withPort(int|null $port)

Modify the port component

Creates a new URL and modifies its port component.

Parameters

int|null $port

Return Value

Url

Exceptions

InvalidUrlException

string getPath()

Retrieve the path component

Retrieves the path component.

Return Value

string

Returns the path component as a string.

Url withPath(string $path)

Modify the path component

Creates a new URL and modifies its path component.

Parameters

string $path

Return Value

Url

Exceptions

InvalidUrlException

string|null getQuery()

Retrieve the query component

Retrieves the query component.

Return Value

string|null

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

Url withQuery(string|null $query)

Modify the query component

Creates a new URL and modifies its query component.

Parameters

string|null $query

Return Value

Url

Exceptions

InvalidUrlException

string|null getFragment()

Retrieve the fragment component

Retrieves the fragment component.

Return Value

string|null

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

Url withFragment(string|null $fragment)

Modify the fragment component

Creates a new URL and modifies its fragment component.

Parameters

string|null $fragment

Return Value

Url

Exceptions

InvalidUrlException

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

Check if two URLs are equivalent

Checks if two URLs are equivalent.

Parameters

Url $url

URL to compare the current URL 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 URLs are equivalent, or false otherwise.

string toAsciiString()

Recompose the URL as an ASCII string

Recomposes the URL as an ASCII string, using punycode transcription instead of Unicode characters in the host component.

Return Value

string

Returns the recomposed URL as an ASCII string.

string toUnicodeString()

Recompose the URL as a Unicode string

Recomposes the URL as a string, where the host component may contain Unicode characters.

Return Value

string

Returns the recomposed URL as a Unicode string.

Url resolve(string $uri, array $softErrors = null)

Resolve a URL with the current object as the base URL

Resolves a valid URL string - which may potentially be a relative-URL string - with the current object as the base URL.

Parameters

string $uri

A valid URL string (e.g. /foo or (e.g. https://example.com/foo) to apply on the current object.

array $softErrors

An array to pass a list of Uri\WhatWg\UrlValidationError instances by reference to provide extended information about the soft errors triggered during reference resolution.

Return Value

Url

Exceptions

InvalidUrlException

array __serialize()

Serialize the Url object

Serializes the Uri\WhatWg\Url object.

Return Value

array

Exceptions

Exception

void __unserialize(array $data)

Deserialize the data parameter into a Url object

Deserializes a data parameter into a Uri\WhatWg\Url object.

Parameters

array $data

Return Value

void

Exceptions

Exception

array __debugInfo()

Return the internal state of the URL

Returns the internal state of the URL.

Return Value

array

Returns the internal state of the URL as an array.

UrlHostType|null getHostType()

Since: 8.6

No description

Return Value

UrlHostType|null

bool isSpecialScheme()

Since: 8.6

No description

Return Value

bool