Fully Qualified Name: | Laminas\Uri\Http |
Extends: | Uri |
HTTP URI handler
Name | Description | Defined By |
---|---|---|
__construct() | Create a new URI object | Uri |
__toString() | Magic method to convert the URI to a string | Uri |
encodePath() | Encode the path | Uri |
encodeQueryFragment() | URL-encode a query string or fragment based on RFC-3986 guidelines. | Uri |
encodeUserInfo() | URL-encode the user info part of a URI | Uri |
getEscaper() | Retrieve Escaper instance | Uri |
getFragment() | Get the URI fragment | Uri |
getHost() | Get the URI host | Uri |
getPassword() | Get the password part (after the ':') of the userInfo URI part | Http |
getPath() | Get the URI path | Uri |
getPort() | Return the URI port | Http |
getQuery() | Get the URI query | Uri |
getQueryAsArray() | Return the query string as an associative array of key => value pairs | Uri |
getScheme() | Get the scheme part of the URI | Uri |
getUser() | Get the username part (before the ':') of the userInfo URI part | Http |
getUserInfo() | Get the User-info (usually user:password) part | Http |
isAbsolute() | Check if the URI is an absolute or relative URI | Uri |
isValid() | Check if the URI is valid | Uri |
isValidRelative() | Check if the URI is a valid relative URI | Uri |
makeRelative() | Convert the link to a relative link by substracting a base URI | Uri |
merge() | Merge a base URI and a relative URI into a new URI object | Uri |
normalize() | Normalize the URI | Uri |
parse() | Parse a URI string | Http |
parseScheme() | Extract only the scheme part out of a URI string. | Uri |
removePathDotSegments() | Remove any extra dot segments (/. | Uri |
resolve() | Convert a relative URI into an absolute URI using a base absolute URI as a reference. | Uri |
setEscaper() | Set Escaper instance | Uri |
setFragment() | Set the URI fragment part | Uri |
setHost() | Set the URI host | Uri |
setPassword() | Set the password part (after the ':') of the userInfo URI part | Http |
setPath() | Set the path | Uri |
setPort() | Set the port part of the URI | Uri |
setQuery() | Set the query string | Uri |
setScheme() | Set the URI scheme | Uri |
setUser() | Set the username part (before the ':') of the userInfo URI part | Http |
setUserInfo() | Set the URI User-info part (usually user:password) | Http |
toString() | Compose the URI into a string | Uri |
validateHost() | Validate the host part of an HTTP URI | Http |
validatePath() | Validate the path | Uri |
validatePort() | Validate the port | Uri |
validateQueryFragment() | Check if a URI query or fragment part is valid or not | Uri |
validateScheme() | Check if a scheme is valid or not | Uri |
validateUserInfo() | Check that the userInfo part of a URI is valid | Uri |
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
Encode the path
Will replace all characters which are not strictly allowed in the path part with percent-encoded representation
Parameter Name | Type | Description |
---|---|---|
$path | string |
Returns: string
URL-encode a query string or fragment based on RFC-3986 guidelines.
Note that query and fragment encoding allows more unencoded characters than the usual rawurlencode() function would usually return - for example '/' and ':' are allowed as literals.
Parameter Name | Type | Description |
---|---|---|
$input | string |
Returns: string
URL-encode the user info part of a URI
Parameter Name | Type | Description |
---|---|---|
$userInfo | string |
Returns: string
Retrieve Escaper instance
Lazy-loads one if none provided
Returns: \Escaper
Get the URI fragment
Returns: string|null
Get the URI host
Returns: string|null
Get the password part (after the ':') of the userInfo URI part
Returns: string|null
Get the URI path
Returns: string|null
Return the URI port
If no port is set, will return the default port according to the scheme
Returns: int
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 username part (before the ':') of the userInfo URI part
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
Merge a base URI and a relative URI into a new URI object
This convenience method wraps ::resolve() to allow users to quickly create new absolute URLs without the need to instantiate and clone URI objects.
If objects are passed in, none of the passed objects will be modified.
Parameter Name | Type | Description |
---|---|---|
$baseUri | \Uri|string | |
$relativeUri | \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: \Http
Extract only the scheme part out of a URI string.
This is used by the parse() method, but is useful as a standalone public method if one wants to test a URI string for it's scheme before doing anything with it.
Will return the scheme if found, or NULL if no scheme found (URI may still be valid, but not full)
Parameter Name | Type | Description |
---|---|---|
$uriString | string |
Returns: string|null
Remove any extra dot segments (/.
./, /./) from a path
Algorithm is adapted from RFC-3986 section 5.2.4 (@link http://tools.ietf.org/html/rfc3986#section-5.2.4)
Parameter Name | Type | Description |
---|---|---|
$path | string |
Returns: string
Convert a relative URI into an absolute URI using a base absolute URI as a reference.
This is similar to merge() - only it uses the supplied URI as the base reference instead of using the current URI as the base reference.
Merging algorithm is adapted from RFC-3986 section 5.2 (@link http://tools.ietf.org/html/rfc3986#section-5.2)
Parameter Name | Type | Description |
---|---|---|
$baseUri | \Uri|string |
Returns: \Uri
Set Escaper instance
Parameter Name | Type | Description |
---|---|---|
$escaper | \Escaper |
Returns:
Set the URI fragment part
Parameter Name | Type | Description |
---|---|---|
$fragment | string|null |
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|null |
Returns: \Uri
Set the password part (after the ':') of the userInfo URI part
Parameter Name | Type | Description |
---|---|---|
$password | string |
Returns: self
Set the path
Parameter Name | Type | Description |
---|---|---|
$path | string|null |
Returns: \Uri
Set the port part of the URI
Parameter Name | Type | Description |
---|---|---|
$port | int|null |
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|null |
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 Laminas\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|null |
Returns: \Uri
Set the username part (before the ':') of the userInfo URI part
Parameter Name | Type | Description |
---|---|---|
$user | string|null |
Returns: self
Set the URI User-info part (usually user:password)
Parameter Name | Type | Description |
---|---|---|
$userInfo | string|null |
Returns: self
Compose the URI into a string
Returns: string
Validate the host part of an HTTP URI
This overrides the common URI validation method with a DNS or IP only default. Users may still enforce allowing other host types.
Parameter Name | Type | Description |
---|---|---|
$host | string | |
$allowed | int |
Returns: bool
Validate the path
Parameter Name | Type | Description |
---|---|---|
$path | string |
Returns: bool
Validate the port
Valid values include numbers between 1 and 65535, and empty values
Parameter Name | Type | Description |
---|---|---|
$port | int |
Returns: bool
Check if a URI query or fragment part is valid or not
Query and Fragment parts are both restricted by the same syntax rules, so the same validation method can be used for both.
You can encode a query or fragment part to ensure it is valid by passing it through the encodeQueryFragment() method.
Parameter Name | Type | Description |
---|---|---|
$input | string |
Returns: bool
Check if a scheme is valid or not
Will check $scheme to be valid against the generic scheme syntax defined in RFC-3986. If the class also defines specific acceptable schemes, will also check that $scheme is one of them.
Parameter Name | Type | Description |
---|---|---|
$scheme | string |
Returns: bool
Check that the userInfo part of a URI is valid
Parameter Name | Type | Description |
---|---|---|
$userInfo | string |
Returns: bool