Interface defining an URI

 Methods

Create a new URI object

__construct(\Zend\Uri\Uri | string | null $uri) 

Parameters

$uri

\Zend\Uri\Uristringnull

Exceptions

\Zend\Uri\Exception\InvalidArgumentException

Magic method to convert the URI to a string

__toString() : string

Returns

string

Get the URI fragment

getFragment() : string | null

Returns

stringnull

Get the URI host

getHost() : string | null

Returns

stringnull

Get the URI path

getPath() : string | null

Returns

stringnull

Get the URI port

getPort() : integer | null

Returns

integernull

Get the URI query

getQuery() : string | null

Returns

stringnull

Return the query string as an associative array of key => value pairs

getQueryAsArray() : array

This is an extension to RFC-3986 but is quite useful when working with most common URI types

Returns

array

Get the scheme part of the URI

getScheme() : string | null

Returns

stringnull

Get the User-info (usually user:password) part

getUserInfo() : string | null

Returns

stringnull

Check if the URI is an absolute or relative URI

isAbsolute() : bool

Returns

bool

Check if the URI is valid

isValid() : bool

Note that a relative URI may still be valid

Returns

bool

Check if the URI is a valid relative URI

isValidRelative() : bool

Returns

bool

Convert the link to a relative link by substracting a base URI

makeRelative(\Zend\Uri\Uri | string $baseUri) : \Zend\Uri\Uri

This is the opposite of resolving a relative link - i.e. creating a relative reference link from an original URI and a base URI.

If the two URIs do not intersect (e.g. the original URI is not in any way related to the base URI) the URI will not be modified.

Parameters

$baseUri

\Zend\Uri\Uristring

Returns

Normalize the URI

normalize() : \Zend\Uri\Uri

Normalizing a URI includes removing any redundant parent directory or current directory references from the path (e.g. foo/bar/../baz becomes foo/baz), normalizing the scheme case, decoding any over-encoded characters etc.

Eventually, two normalized URLs pointing to the same resource should be equal even if they were originally represented by two different strings

Returns

Parse a URI string

parse(string $uri) : \Zend\Uri\Uri

Parameters

$uri

string

Returns

Set the URI fragment part

setFragment(string $fragment) : \Zend\Uri\Uri

Parameters

$fragment

string

Exceptions

\Zend\Uri\Exception\InvalidUriPartException If the schema definition does not have this part

Returns

Set the URI host

setHost(string $host) : \Zend\Uri\Uri

Note that the generic syntax for URIs allows using host names which are not necessarily IPv4 addresses or valid DNS host names. For example, IPv6 addresses are allowed as well, and also an abstract "registered name" which may be any name composed of a valid set of characters, including, for example, tilda (~) and underscore (_) which are not allowed in DNS names.

Subclasses of Uri may impose more strict validation of host names - for example the HTTP RFC clearly states that only IPv4 and valid DNS names are allowed in HTTP URIs.

Parameters

$host

string

Exceptions

\Zend\Uri\Exception\InvalidUriPartException

Returns

Set the path

setPath(string $path) : \Zend\Uri\Uri

Parameters

$path

string

Returns

Set the port part of the URI

setPort(integer $port) : \Zend\Uri\Uri

Parameters

$port

integer

Returns

Set the query string

setQuery(string | array $query) : \Zend\Uri\Uri

If an array is provided, will encode this array of parameters into a query string. Array values will be represented in the query string using PHP's common square bracket notation.

Parameters

$query

stringarray

Returns

Set the URI scheme

setScheme(string $scheme) : \Zend\Uri\Uri

If the scheme is not valid according to the generic scheme syntax or is not acceptable by the specific URI class (e.g. 'http' or 'https' are the only acceptable schemes for the Zend\Uri\Http class) an exception will be thrown.

You can check if a scheme is valid before setting it using the validateScheme() method.

Parameters

$scheme

string

Exceptions

\Zend\Uri\Exception\InvalidUriPartException

Returns

Set the URI User-info part (usually user:password)

setUserInfo(string $userInfo) : \Zend\Uri\Uri

Parameters

$userInfo

string

Exceptions

\Zend\Uri\Exception\InvalidUriPartException If the schema definition does not have this part

Returns

Compose the URI into a string

toString() : string

Exceptions

\Zend\Uri\Exception\InvalidUriException

Returns

string