Fully Qualified Name: | Zend\Uri\UriInterface |
Interface defining a URI
Name | Description | Defined By |
---|---|---|
__construct() | Create a new URI object | UriInterface |
__toString() | Magic method to convert the URI to a string | UriInterface |
getFragment() | Get the URI fragment | UriInterface |
getHost() | Get the URI host | UriInterface |
getPath() | Get the URI path | UriInterface |
getPort() | Get the URI port | UriInterface |
getQuery() | Get the URI query | UriInterface |
getQueryAsArray() | Return the query string as an associative array of key => value pairs | UriInterface |
getScheme() | Get the scheme part of the URI | UriInterface |
getUserInfo() | Get the User-info (usually user:password) part | UriInterface |
isAbsolute() | Check if the URI is an absolute or relative URI | UriInterface |
isValid() | Check if the URI is valid | UriInterface |
isValidRelative() | Check if the URI is a valid relative URI | UriInterface |
makeRelative() | Convert the link to a relative link by substracting a base URI | UriInterface |
normalize() | Normalize the URI | UriInterface |
parse() | Parse a URI string | UriInterface |
setFragment() | Set the URI fragment part | UriInterface |
setHost() | Set the URI host | UriInterface |
setPath() | Set the path | UriInterface |
setPort() | Set the port part of the URI | UriInterface |
setQuery() | Set the query string | UriInterface |
setScheme() | Set the URI scheme | UriInterface |
setUserInfo() | Set the URI User-info part (usually user:password) | UriInterface |
toString() | Compose the URI into a string | UriInterface |
Create a new URI object
Parameter Name | Type | Description |
---|---|---|
$uri | \Uri|string|null |
Returns:
Magic method to convert the URI to a string
Returns: string
Get the URI fragment
Returns: string|null
Get the URI host
Returns: string|null
Get the URI path
Returns: string|null
Get the URI port
Returns: int|null
Get the URI query
Returns: string|null
Return the query string as an associative array of key => value pairs
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
Returns: string|null
Get the User-info (usually user:password) part
Returns: string|null
Check if the URI is an absolute or relative URI
Returns: bool
Check if the URI is valid
Note that a relative URI may still be valid
Returns: bool
Check if the URI is a valid relative URI
Returns: bool
Convert the link to a relative link by substracting a base 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.
Parameter Name | Type | Description |
---|---|---|
$baseUri | \Uri|string |
Returns: \Uri
Normalize the 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: \Uri
Parse a URI string
Parameter Name | Type | Description |
---|---|---|
$uri | string |
Returns: \Uri
Set the URI fragment part
Parameter Name | Type | Description |
---|---|---|
$fragment | string |
Returns: \Uri
Set the URI host
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.
Parameter Name | Type | Description |
---|---|---|
$host | string |
Returns: \Uri
Set the path
Parameter Name | Type | Description |
---|---|---|
$path | string |
Returns: \Uri
Set the port part of the URI
Parameter Name | Type | Description |
---|---|---|
$port | int |
Returns: \Uri
Set the query string
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.
Parameter Name | Type | Description |
---|---|---|
$query | string|array |
Returns: \Uri
Set the URI scheme
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.
Parameter Name | Type | Description |
---|---|---|
$scheme | string |
Returns: \Uri
Set the URI User-info part (usually user:password)
Parameter Name | Type | Description |
---|---|---|
$userInfo | string |
Returns: \Uri
Compose the URI into a string
Returns: string