Generic URI handler
Create a new URI object
Parameters: | Uri|string|null – |
---|---|
Throws ExceptionInvalidArgumentException: | |
Retrieve Escaper instance
Lazy-loads one if none provided
Return type: | Escaper |
---|
Check if the URI is valid
Note that a relative URI may still be valid
Return type: | bool |
---|
Check if the URI is a valid relative URI
Return type: | bool |
---|
Check if the URI is an absolute or relative URI
Return type: | bool |
---|
Parse a URI string
Parameters: | string – |
---|---|
Return type: | Uri |
Compose the URI into a string
Return type: | string |
---|---|
Throws : | ExceptionInvalidUriException |
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
Return type: | Uri |
---|
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)
Parameters: | Uri|string – |
---|---|
Throws ExceptionInvalidArgumentException: | |
Return type: | Uri |
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.
Parameters: | Uri|string – |
---|---|
Return type: | Uri |
Get the User-info (usually user:password) part
Return type: | 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
Return type: | array |
---|
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 ZendUriHttp class) an exception will be thrown.
You can check if a scheme is valid before setting it using the validateScheme() method.
Parameters: | string – |
---|---|
Throws ExceptionInvalidUriPartException: | |
Return type: | Uri |
Set the URI User-info part (usually user:password)
Parameters: | string – |
---|---|
Return type: | Uri |
Throws : | ExceptionInvalidUriPartException If the schema definition |
does not have this part
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.
Parameters: | string – |
---|---|
Throws ExceptionInvalidUriPartException: | |
Return type: | 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.
Parameters: | string|array – |
---|---|
Return type: | Uri |
Set the URI fragment part
Parameters: | string – |
---|---|
Return type: | Uri |
Throws : | ExceptionInvalidUriPartException If the schema definition |
does not have this part
Magic method to convert the URI to a string
Return type: | string |
---|
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.
Parameters: | string – |
---|---|
Return type: | bool |
Check that the userInfo part of a URI is valid
Parameters: | string – |
---|---|
Return type: | bool |
Validate the host part
Users may control which host types to allow by passing a second parameter with a bitmask of HOST_* constants which are allowed. If not specified, all address types will be allowed.
Note that the generic URI syntax allows different host representations, including IPv4 addresses, IPv6 addresses and future IP address formats enclosed in square brackets, and registered names which may be DNS names or even more complex names. This is different (and is much more loose) from what is commonly accepted as valid HTTP URLs for example.
Parameters: |
|
---|---|
Return type: | bool |
Validate the port
Valid values include numbers between 1 and 65535, and empty values
Parameters: | integer – |
---|---|
Return type: | 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.
Parameters: | string – |
---|---|
Return type: | bool |
URL-encode the user info part of a URI
Parameters: | string – |
---|---|
Return type: | string |
Throws : | ExceptionInvalidArgumentException |
Encode the path
Will replace all characters which are not strictly allowed in the path part with percent-encoded representation
Parameters: | string – |
---|---|
Throws ExceptionInvalidArgumentException: | |
Return type: | 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.
Parameters: | string – |
---|---|
Return type: | string |
Throws : | ExceptionInvalidArgumentException |
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)
Parameters: | string – |
---|---|
Throws ExceptionInvalidArgumentException: | |
Return type: | 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)
Parameters: | string – |
---|---|
Return type: | string |
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.
Parameters: |
|
---|---|
Return type: | Uri |
Check if a host name is a valid IP address, depending on allowed IP address types
Parameters: |
|
---|---|
Return type: | bool |
Check if an address is a valid DNS hostname
Parameters: | string – |
---|---|
Return type: | bool |
Check if an address is a valid registered name (as defined by RFC-3986) address
Parameters: | string – |
---|---|
Return type: | bool |
Normalize the scheme
Usually this means simply converting the scheme to lower case
Parameters: | string – |
---|---|
Return type: | string |
Normalize the host part
By default this converts host names to lower case
Parameters: | string – |
---|---|
Return type: | string |
Normalize the port
If the class defines a default port for the current scheme, and the current port is default, it will be unset.
Parameters: |
|
---|---|
Return type: | integer|null |
Normalize the path
This involves removing redundant dot segments, decoding any over-encoded characters and encoding everything that needs to be encoded and is not
Parameters: | string – |
---|---|
Return type: | string |
Normalize the query part
This involves decoding everything that doesn’t need to be encoded, and encoding everything else
Parameters: | string – |
---|---|
Return type: | string |
Character classes defined in RFC-3986
Host part types represented as binary masks The binary mask consists of 5 bits in the following order: <RegName> | <DNS> | <IPvFuture> | <IPv6> | <IPv4> Place 1 or 0 in the different positions for enable or disable the part. Finally use a hexadecimal representation.