UriInterface
in
Interface defining a URI
Table of Contents
Methods
- __construct() : mixed
- Create a new URI object
- __toString() : string
- Magic method to convert the URI to a string
- getFragment() : string|null
- Get the URI fragment
- getHost() : string|null
- Get the URI host
- getPath() : string|null
- Get the URI path
- getPort() : int|null
- Get the URI port
- getQuery() : string|null
- Get the URI query
- getQueryAsArray() : array<string|int, mixed>
- Return the query string as an associative array of key => value pairs
- getScheme() : string|null
- Get the scheme part of the URI
- getUserInfo() : string|null
- Get the User-info (usually user:password) part
- isAbsolute() : bool
- Check if the URI is an absolute or relative URI
- isValid() : bool
- Check if the URI is valid
- isValidRelative() : bool
- Check if the URI is a valid relative URI
- makeRelative() : Uri
- Convert the link to a relative link by substracting a base URI
- normalize() : Uri
- Normalize the URI
- parse() : Uri
- Parse a URI string
- setFragment() : Uri
- Set the URI fragment part
- setHost() : Uri
- Set the URI host
- setPath() : Uri
- Set the path
- setPort() : Uri
- Set the port part of the URI
- setQuery() : Uri
- Set the query string
- setScheme() : Uri
- Set the URI scheme
- setUserInfo() : Uri
- Set the URI User-info part (usually user:password)
- toString() : string
- Compose the URI into a string
Methods
__construct()
Create a new URI object
public
__construct([Uri|string|null $uri = null ]) : mixed
Parameters
- $uri : Uri|string|null = null
Tags
__toString()
Magic method to convert the URI to a string
public
__toString() : string
Return values
stringgetFragment()
Get the URI fragment
public
getFragment() : string|null
Return values
string|nullgetHost()
Get the URI host
public
getHost() : string|null
Return values
string|nullgetPath()
Get the URI path
public
getPath() : string|null
Return values
string|nullgetPort()
Get the URI port
public
getPort() : int|null
Return values
int|nullgetQuery()
Get the URI query
public
getQuery() : string|null
Return values
string|nullgetQueryAsArray()
Return the query string as an associative array of key => value pairs
public
getQueryAsArray() : array<string|int, mixed>
This is an extension to RFC-3986 but is quite useful when working with most common URI types
Return values
array<string|int, mixed>getScheme()
Get the scheme part of the URI
public
getScheme() : string|null
Return values
string|nullgetUserInfo()
Get the User-info (usually user:password) part
public
getUserInfo() : string|null
Return values
string|nullisAbsolute()
Check if the URI is an absolute or relative URI
public
isAbsolute() : bool
Return values
boolisValid()
Check if the URI is valid
public
isValid() : bool
Note that a relative URI may still be valid
Return values
boolisValidRelative()
Check if the URI is a valid relative URI
public
isValidRelative() : bool
Return values
boolmakeRelative()
Convert the link to a relative link by substracting a base URI
public
makeRelative(Uri|string $baseUri) : 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 : Uri|string
Return values
Urinormalize()
Normalize the URI
public
normalize() : 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
Return values
Uriparse()
Parse a URI string
public
parse(string $uri) : Uri
Parameters
- $uri : string
Return values
UrisetFragment()
Set the URI fragment part
public
setFragment(string $fragment) : Uri
Parameters
- $fragment : string
Tags
Return values
UrisetHost()
Set the URI host
public
setHost(string $host) : 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
Tags
Return values
UrisetPath()
Set the path
public
setPath(string $path) : Uri
Parameters
- $path : string
Return values
UrisetPort()
Set the port part of the URI
public
setPort(int $port) : Uri
Parameters
- $port : int
Return values
UrisetQuery()
Set the query string
public
setQuery(string|array<string|int, mixed> $query) : 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 : string|array<string|int, mixed>
Return values
UrisetScheme()
Set the URI scheme
public
setScheme(string $scheme) : 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 Laminas\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
Tags
Return values
UrisetUserInfo()
Set the URI User-info part (usually user:password)
public
setUserInfo(string $userInfo) : Uri
Parameters
- $userInfo : string
Tags
Return values
UritoString()
Compose the URI into a string
public
toString() : string