class Url implements JsonSerializable

Mutable representation of a URL.

scheme  user  password  host  port      path        query    fragment
  |      |      |        |      |        |            |         |
/--\   /--\ /------\ /-------\ /--\/------------\ /--------\ /------\
http://john:x0y17575@nette.org:8042/en/manual.php?name=param#fragment  <-- absoluteUrl
\______\__________________________/
    |               |
 hostUrl        authority

Properties

static array<string,int> $defaultPorts
string $scheme
string $user
string $password
string $host
int $port
string $path
string $query
string $fragment
string read-only $absoluteUrl
string read-only $authority
string read-only $hostUrl
string read-only $basePath
string read-only $baseUrl
string read-only $relativeUrl
array<string,mixed> read-only $queryParameters

Methods

__construct(UrlImmutable|null $url = null)

No description

Url
setScheme(string $scheme)

No description

string
getScheme()

No description

Url
setUser(string $user)

No description

string
getUser()

No description

Url
setPassword(string $password)

No description

string
getPassword()

No description

Url
setHost(string $host)

No description

string
getHost()

No description

string
getDomain(int $level = 2)

Returns the specified number of rightmost domain labels (e.g. level 2 of 'www.nette.org' -> 'nette.org').

Url
setPort(int $port)

No description

int|null
getPort()

Returns the port number, falling back to the default port for the scheme if not explicitly set.

int|null
getDefaultPort()

Returns the default port for the current scheme, or null if the scheme is not recognized.

Url
setPath(string $path)

Sets the path. Automatically prepends a leading slash when a host is set.

string
getPath()

No description

Url
setQuery(string|array $query)

No description

Url
appendQuery(string|array $query)

Merges query parameters into the existing query. Array values use union (existing keys are preserved); string values are appended and reparsed.

string
getQuery()

No description

array
getQueryParameters()

No description

mixed
getQueryParameter(string $name)

No description

Url
setQueryParameter(string $name, mixed $value)

No description

Url
setFragment(string $fragment)

No description

string
getFragment()

No description

string
getAbsoluteUrl()

No description

string
getAuthority()

Returns the [user[:pass]@]host[:port] part of URI.

string
getHostUrl()

Returns the scheme and authority part of URI.

string
getBasePath()

No description

string
getBaseUrl()

No description

string
getRelativeUrl()

No description

bool
isEqual(UrlImmutable $url)

Checks whether two URLs are equal, ignoring query parameter order and trailing dots in hostnames.

Url
canonicalize()

Normalizes the URL to canonical form: percent-encodes path, lowercases and trims the host, and converts IDN ASCII to Unicode.

string
__toString()

No description

string
jsonSerialize()

No description

array
export()

No description

static string
unescape(string $s, string $reserved = '%;/?:@&=+$,')

Decodes percent-encoded characters, but keeps reserved characters (specified in $reserved) encoded.

static array
parseQuery(string $s)

Parses query string. Is affected by directive arg_separator.input.

static bool
isAbsolute(string $url)

Checks whether the URL is absolute, i.e. starts with a scheme followed by a colon.

static string
removeDotSegments(string $path)

Resolves dot segments (. and ..) in a URL path, as per RFC 3986.

Details

at line 70
__construct(UrlImmutable|null $url = null)

No description

Parameters

UrlImmutable|null $url

Exceptions

InvalidArgumentException

at line 93
Url setScheme(string $scheme)

No description

Parameters

string $scheme

Return Value

Url

at line 100
string getScheme()

No description

Return Value

string

at line 106
Url setUser(string $user)

No description

Parameters

string $user

Return Value

Url

at line 115
string getUser()

No description

Return Value

string

at line 123
Url setPassword(string $password)

No description

Parameters

string $password

Return Value

Url

at line 132
string getPassword()

No description

Return Value

string

at line 140
Url setHost(string $host)

No description

Parameters

string $host

Return Value

Url

at line 148
string getHost()

No description

Return Value

string

at line 158
string getDomain(int $level = 2)

Returns the specified number of rightmost domain labels (e.g. level 2 of 'www.nette.org' -> 'nette.org').

Negative values trim from the right instead.

Parameters

int $level

Return Value

string

at line 170
Url setPort(int $port)

No description

Parameters

int $port

Return Value

Url

at line 180
int|null getPort()

Returns the port number, falling back to the default port for the scheme if not explicitly set.

Return Value

int|null

at line 189
int|null getDefaultPort()

Returns the default port for the current scheme, or null if the scheme is not recognized.

Return Value

int|null

at line 198
Url setPath(string $path)

Sets the path. Automatically prepends a leading slash when a host is set.

Parameters

string $path

Return Value

Url

at line 209
string getPath()

No description

Return Value

string

at line 216
Url setQuery(string|array $query)

No description

Parameters

string|array $query

Return Value

Url

at line 228
Url appendQuery(string|array $query)

Merges query parameters into the existing query. Array values use union (existing keys are preserved); string values are appended and reparsed.

Parameters

string|array $query

Return Value

Url

at line 237
string getQuery()

No description

Return Value

string

at line 244
array getQueryParameters()

No description

Return Value

array

at line 250
mixed getQueryParameter(string $name)

No description

Parameters

string $name

Return Value

mixed

at line 256
Url setQueryParameter(string $name, mixed $value)

No description

Parameters

string $name
mixed $value

Return Value

Url

at line 263
Url setFragment(string $fragment)

No description

Parameters

string $fragment

Return Value

Url

at line 270
string getFragment()

No description

Return Value

string

at line 276
string getAbsoluteUrl()

No description

Return Value

string

at line 287
string getAuthority()

Returns the [user[:pass]@]host[:port] part of URI.

Return Value

string

at line 304
string getHostUrl()

Returns the scheme and authority part of URI.

Return Value

string

at line 311
string getBasePath()

No description

Return Value

string

at line 320
string getBaseUrl()

No description

Return Value

string

at line 328
string getRelativeUrl()

No description

Return Value

string

at line 339
bool isEqual(UrlImmutable $url)

Checks whether two URLs are equal, ignoring query parameter order and trailing dots in hostnames.

Parameters

UrlImmutable $url

Return Value

bool

at line 364
Url canonicalize()

Normalizes the URL to canonical form: percent-encodes path, lowercases and trims the host, and converts IDN ASCII to Unicode.

Return Value

Url

at line 377
string __toString()

No description

Return Value

string

at line 383
string jsonSerialize()

No description

Return Value

string

at line 393
final array export()

internal  
 

No description

Return Value

array

at line 420
static string unescape(string $s, string $reserved = '%;/?:@&=+$,')

Decodes percent-encoded characters, but keeps reserved characters (specified in $reserved) encoded.

Parameters

string $s
string $reserved

Return Value

string

at line 441
static array parseQuery(string $s)

Parses query string. Is affected by directive arg_separator.input.

Parameters

string $s

Return Value

array

at line 454
static bool isAbsolute(string $url)

Checks whether the URL is absolute, i.e. starts with a scheme followed by a colon.

Parameters

string $url

Return Value

bool

at line 463
static string removeDotSegments(string $path)

Resolves dot segments (. and ..) in a URL path, as per RFC 3986.

Parameters

string $path

Return Value

string

Traits

SmartObject