Class URI

Summary

Fully Qualified Name: CodeIgniter\HTTP\URI

Description

Abstraction for a uniform resource identifier (URI).

Methods

Name Description Defined By
__construct() Constructor. URI
__toString() Allow the URI to be output as a string by simply casting it to a string or echoing out. URI
addQuery() Adds a single new element to the query vars. URI
createURIString() Builds a representation of the string from the component parts. URI
getAuthority() Retrieve the authority component of the URI. URI
getFragment() Retrieve a URI fragment URI
getHost() Retrieve the host component of the URI. URI
getPath() Retrieve the path component of the URI. URI
getPort() Retrieve the port component of the URI. URI
getQuery() Retrieve the query string URI
getScheme() Retrieve the scheme component of the URI. URI
getSegment() Returns the value of a specific segment of the URI path. URI
getSegments() Returns the segments of the path as an array. URI
getTotalSegments() Returns the total number of segments. URI
getUserInfo() Retrieve the user information component of the URI. URI
keepQuery() Filters the query variables so that only the keys passed in are kept. The rest are removed from the object. URI
refreshPath() Sets the path portion of the URI based on segments. URI
removeDotSegments() Used when resolving and merging paths to correctly interpret and remove single and double dot segments from the path per RFC 3986 Section 5.2.4 URI
resolveRelativeURI() Combines one URI string with this one based on the rules set out in RFC 3986 Section 2 URI
setAuthority() Parses the given string an saves the appropriate authority pieces. URI
setFragment() Sets the fragment portion of the URI. URI
setHost() Sets the host name to use. URI
setPath() Sets the path portion of the URI. URI
setPort() Sets the port portion of the URI. URI
setQuery() Sets the query portion of the URI, while attempting to clean the various parts of the query keys and values. URI
setQueryArray() A convenience method to pass an array of items in as the Query portion of the URI. URI
setScheme() Sets the scheme for this URI. URI
setSegment() Set the value of a specific segment of the URI path. URI
setURI() Sets and overwrites any current URI information. URI
setUserInfo() Sets the userInfo/Authority portion of the URI. URI
showPassword() Temporarily sets the URI to show a password in userInfo. Will reset itself after the first call to authority(). URI
stripQuery() Removes one or more query vars from the URI. URI

Method Details

__construct()

Constructor.

Parameter Name Type Description
$uri string

Returns:

__toString()

Allow the URI to be output as a string by simply casting it to a string or echoing out.

Returns:

addQuery()

Adds a single new element to the query vars.

Parameter Name Type Description
$key string
$value mixed

Returns: $this

createURIString()

Builds a representation of the string from the component parts.

Parameter Name Type Description
$scheme string
$authority string
$path string
$query string
$fragment string

Returns: string

getAuthority()

Retrieve the authority component of the URI.

If no authority information is present, this method MUST return an empty string.

The authority syntax of the URI is:

[user-info@]host[:port]

If the port component is not set or is the standard port for the current scheme, it SHOULD NOT be included.

Parameter Name Type Description
$ignorePort bool

Returns: string The URI authority, in "[user-info@]host[:port]" format.

getFragment()

Retrieve a URI fragment

Returns: string

getHost()

Retrieve the host component of the URI.

If no host is present, this method MUST return an empty string.

The value returned MUST be normalized to lowercase, per RFC 3986 Section 3.2.2.

Returns: string The URI host.

getPath()

Retrieve the path component of the URI.

The path can either be empty or absolute (starting with a slash) or rootless (not starting with a slash). Implementations MUST support all three syntaxes.

Normally, the empty path "" and absolute path "/" are considered equal as defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically do this normalization because in contexts with a trimmed base path, e.g. the front controller, this difference becomes significant. It's the task of the user to handle both "" and "/".

The value returned MUST be percent-encoded, but MUST NOT double-encode any characters. To determine what characters to encode, please refer to RFC 3986, Sections 2 and 3.3.

As an example, if the value should include a slash ("/") not intended as delimiter between path segments, that value MUST be passed in encoded form (e.g., "%2F") to the instance.

Returns: string The URI path.

getPort()

Retrieve the port component of the URI.

If a port is present, and it is non-standard for the current scheme, this method MUST return it as an integer. If the port is the standard port used with the current scheme, this method SHOULD return null.

If no port is present, and no scheme is present, this method MUST return a null value.

If no port is present, but a scheme is present, this method MAY return the standard port for that scheme, but SHOULD return null.

Returns: null|int The URI port.

getQuery()

Retrieve the query string

Parameter Name Type Description
$options array

Returns: string

getScheme()

Retrieve the scheme component of the URI.

If no scheme is present, this method MUST return an empty string.

The value returned MUST be normalized to lowercase, per RFC 3986 Section 3.1.

The trailing ":" character is not part of the scheme and MUST NOT be added.

Returns: string The URI scheme.

getSegment()

Returns the value of a specific segment of the URI path.

Parameter Name Type Description
$number int

Returns: string The value of the segment. If no segment is found, throws InvalidArgumentError

getSegments()

Returns the segments of the path as an array.

Returns: array

getTotalSegments()

Returns the total number of segments.

Returns: int

getUserInfo()

Retrieve the user information component of the URI.

If no user information is present, this method MUST return an empty string.

If a user is present in the URI, this will return that value; additionally, if the password is also present, it will be appended to the user value, with a colon (":") separating the values.

NOTE that be default, the password, if available, will NOT be shown as a security measure as discussed in RFC 3986, Section 7.5. If you know the password is not a security issue, you can force it to be shown with $this->showPassword();

The trailing "@" character is not part of the user information and MUST NOT be added.

Returns: string|null The URI user information, in "username[:password]" format.

keepQuery()

Filters the query variables so that only the keys passed in are kept. The rest are removed from the object.

Parameter Name Type Description
...$params array
$params

Returns: $this

refreshPath()

Sets the path portion of the URI based on segments.

Parameter Name Type Description
$path string

Returns: $this

removeDotSegments()

Used when resolving and merging paths to correctly interpret and remove single and double dot segments from the path per RFC 3986 Section 5.2.4

Parameter Name Type Description
$path string

Returns: string

resolveRelativeURI()

Combines one URI string with this one based on the rules set out in RFC 3986 Section 2

Parameter Name Type Description
$uri string

Returns: \CodeIgniter\HTTP\URI

setAuthority()

Parses the given string an saves the appropriate authority pieces.

Parameter Name Type Description
$str string

Returns: $this

setFragment()

Sets the fragment portion of the URI.

Parameter Name Type Description
$string string

Returns: $this

setHost()

Sets the host name to use.

Parameter Name Type Description
$str string

Returns: $this

setPath()

Sets the path portion of the URI.

Parameter Name Type Description
$path string

Returns: $this

setPort()

Sets the port portion of the URI.

Parameter Name Type Description
$port int

Returns: $this

setQuery()

Sets the query portion of the URI, while attempting to clean the various parts of the query keys and values.

Parameter Name Type Description
$query string

Returns: $this

setQueryArray()

A convenience method to pass an array of items in as the Query portion of the URI.

Parameter Name Type Description
$query array

Returns: \CodeIgniter\HTTP\URI

setScheme()

Sets the scheme for this URI.

Because of the large number of valid schemes we cannot limit this to only http or https.

Parameter Name Type Description
$str
$str

Returns: $this

setSegment()

Set the value of a specific segment of the URI path.

Allows to set only existing segments or add new one.

Parameter Name Type Description
$number int
$value mixed (string

Returns: $this

setURI()

Sets and overwrites any current URI information.

Parameter Name Type Description
$uri string|null

Returns: \URI

setUserInfo()

Sets the userInfo/Authority portion of the URI.

Parameter Name Type Description
$user string The
$pass string The

Returns: $this

showPassword()

Temporarily sets the URI to show a password in userInfo. Will reset itself after the first call to authority().

Parameter Name Type Description
$val bool

Returns: \URI

stripQuery()

Removes one or more query vars from the URI.

Parameter Name Type Description
...$params array
$params

Returns: $this

Top