1957. Class

1957.1. Zend\Uri\Uri

Generic URI handler

1957.1.1. Methods

1957.1.1.1. __construct

__construct()

Create a new URI object

Parameters:Uri|string|null
Throws ExceptionInvalidArgumentException:
 

1957.1.1.2. setEscaper

setEscaper()

Set Escaper instance

Parameters:Escaper

1957.1.1.3. getEscaper

getEscaper()

Retrieve Escaper instance

Lazy-loads one if none provided

Return type:Escaper

1957.1.1.4. isValid

isValid()

Check if the URI is valid

Note that a relative URI may still be valid

Return type:bool

1957.1.1.5. isValidRelative

isValidRelative()

Check if the URI is a valid relative URI

Return type:bool

1957.1.1.6. isAbsolute

isAbsolute()

Check if the URI is an absolute or relative URI

Return type:bool

1957.1.1.7. parse

parse()

Parse a URI string

Parameters:string
Return type:Uri

1957.1.1.8. toString

toString()

Compose the URI into a string

Return type:string
Throws :ExceptionInvalidUriException

1957.1.1.9. normalize

normalize()

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

1957.1.1.10. resolve

resolve()

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

1957.1.1.11. makeRelative

makeRelative()

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

1957.1.1.12. getScheme

getScheme()

Get the scheme part of the URI

Return type:string|null

1957.1.1.13. getUserInfo

getUserInfo()

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

Return type:string|null

1957.1.1.14. getHost

getHost()

Get the URI host

Return type:string|null

1957.1.1.15. getPort

getPort()

Get the URI port

Return type:integer|null

1957.1.1.16. getPath

getPath()

Get the URI path

Return type:string|null

1957.1.1.17. getQuery

getQuery()

Get the URI query

Return type:string|null

1957.1.1.18. getQueryAsArray

getQueryAsArray()

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

1957.1.1.19. getFragment

getFragment()

Get the URI fragment

Return type:string|null

1957.1.1.20. setScheme

setScheme()

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

1957.1.1.21. setUserInfo

setUserInfo()

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

1957.1.1.22. setHost

setHost()

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

1957.1.1.23. setPort

setPort()

Set the port part of the URI

Parameters:integer
Return type:Uri

1957.1.1.24. setPath

setPath()

Set the path

Parameters:string
Return type:Uri

1957.1.1.25. setQuery

setQuery()

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

1957.1.1.26. setFragment

setFragment()

Set the URI fragment part

Parameters:string
Return type:Uri
Throws :ExceptionInvalidUriPartException If the schema definition

does not have this part

1957.1.1.27. __toString

__toString()

Magic method to convert the URI to a string

Return type:string

1957.1.1.28. validateScheme

validateScheme()

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

1957.1.1.29. validateUserInfo

validateUserInfo()

Check that the userInfo part of a URI is valid

Parameters:string
Return type:bool

1957.1.1.30. validateHost

validateHost()

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:
  • string
  • integer – bitmask of allowed host types
Return type:

bool

1957.1.1.31. validatePort

validatePort()

Validate the port

Valid values include numbers between 1 and 65535, and empty values

Parameters:integer
Return type:bool

1957.1.1.32. validatePath

validatePath()

Validate the path

Parameters:string
Return type:bool

1957.1.1.33. validateQueryFragment

validateQueryFragment()

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

1957.1.1.34. encodeUserInfo

encodeUserInfo()

URL-encode the user info part of a URI

Parameters:string
Return type:string
Throws :ExceptionInvalidArgumentException

1957.1.1.35. encodePath

encodePath()

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

1957.1.1.36. encodeQueryFragment

encodeQueryFragment()

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

1957.1.1.37. parseScheme

parseScheme()

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

1957.1.1.38. removePathDotSegments

removePathDotSegments()

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

1957.1.1.39. merge

merge()

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:
  • Uri|string
  • Uri|string
Return type:

Uri

1957.1.1.40. isValidIpAddress

isValidIpAddress()

Check if a host name is a valid IP address, depending on allowed IP address types

Parameters:
  • string
  • integer – allowed address types
Return type:

bool

1957.1.1.41. isValidDnsHostname

isValidDnsHostname()

Check if an address is a valid DNS hostname

Parameters:string
Return type:bool

1957.1.1.42. isValidRegName

isValidRegName()

Check if an address is a valid registered name (as defined by RFC-3986) address

Parameters:string
Return type:bool

1957.1.1.43. normalizeScheme

normalizeScheme()

Normalize the scheme

Usually this means simply converting the scheme to lower case

Parameters:string
Return type:string

1957.1.1.44. normalizeHost

normalizeHost()

Normalize the host part

By default this converts host names to lower case

Parameters:string
Return type:string

1957.1.1.45. normalizePort

normalizePort()

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:
  • integer
  • string
Return type:

integer|null

1957.1.1.46. normalizePath

normalizePath()

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

1957.1.1.47. normalizeQuery

normalizeQuery()

Normalize the query part

This involves decoding everything that doesn’t need to be encoded, and encoding everything else

Parameters:string
Return type:string

1957.1.1.48. normalizeFragment

normalizeFragment()

Normalize the fragment part

Currently this is exactly the same as normalizeQuery().

Parameters:string
Return type:string

1957.1.1.49. decodeUrlEncodedChars

decodeUrlEncodedChars()

Decode all percent encoded characters which are allowed to be represented literally

Will not decode any characters which are not listed in the ‘allowed’ list

Parameters:
  • string
  • string – Pattern of allowed characters
Return type:

mixed

1957.1.2. Constants

1957.1.2.1. CHAR_UNRESERVED

Character classes defined in RFC-3986

1957.1.2.2. CHAR_GEN_DELIMS

1957.1.2.3. CHAR_SUB_DELIMS

1957.1.2.4. CHAR_RESERVED

1957.1.2.5. HOST_IPV4

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.

1957.1.2.6. HOST_IPV6

1957.1.2.7. HOST_IPVFUTURE

1957.1.2.8. HOST_IPVANY

1957.1.2.9. HOST_DNS

1957.1.2.10. HOST_DNS_OR_IPV4

1957.1.2.11. HOST_DNS_OR_IPV6

1957.1.2.12. HOST_DNS_OR_IPV4_OR_IPV6

1957.1.2.13. HOST_DNS_OR_IPVANY

1957.1.2.14. HOST_REGNAME

1957.1.2.15. HOST_ALL

Project Versions

Table Of Contents

Previous topic

1956. Class

Next topic

1958. Class

This Page