Constants

CHAR_SUB_DELIMS

CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;='

Sub-delimiters used in query strings and fragments.

CHAR_UNRESERVED

CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~'

Unreserved characters used in paths, query strings, and fragments.

Properties

$uriString

$uriString : string

Current URI string

Type

string

$segments

$segments : array

List of URI segments.

Starts at 1 instead of 0

Type

array

$scheme

$scheme : string

The URI Scheme.

Type

string

$user

$user : string

URI User Info

Type

string

$password

$password : string

URI User Password

Type

string

$host

$host : string

URI Host

Type

string

$port

$port : integer

URI Port

Type

integer

$path

$path : string

URI path.

Type

string

$fragment

$fragment : string

The name of any fragment.

Type

string

$query

$query : array

The query string.

Type

array

$defaultPorts

$defaultPorts : array

Default schemes/ports.

Type

array

$showPassword

$showPassword : boolean

Whether passwords should be shown in userInfo/authority calls.

Default to false because URIs often show up in logs

Type

boolean

Methods

__construct()

__construct(string  $uri = null) 

Constructor.

Parameters

string $uri

Throws

\InvalidArgumentException

setURI()

setURI(string|null  $uri = null) : \CodeIgniter\HTTP\URI

Sets and overwrites any current URI information.

Parameters

string|null $uri

Returns

\CodeIgniter\HTTP\URI

getScheme()

getScheme() : string

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.

getAuthority()

getAuthority(boolean  $ignorePort = false) : string

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.

Parameters

boolean $ignorePort

Returns

string —

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

getUserInfo()

getUserInfo() : string|null

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.

showPassword()

showPassword(boolean  $val = true) : \CodeIgniter\HTTP\URI

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

Parameters

boolean $val

Returns

\CodeIgniter\HTTP\URI

getHost()

getHost() : string

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.

getPort()

getPort() : null|integer

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|integer —

The URI port.

getPath()

getPath() : string

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.

getQuery()

getQuery(array  $options = array()) : string

Retrieve the query string

Parameters

array $options

Returns

string

getFragment()

getFragment() : string

Retrieve a URI fragment

Returns

string

getSegments()

getSegments() : array

Returns the segments of the path as an array.

Returns

array

getSegment()

getSegment(integer  $number) : string

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

Parameters

integer $number

Returns

string —

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

setSegment()

setSegment(integer  $number, mixed  $value) : $this

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

Allows to set only existing segments or add new one.

Parameters

integer $number
mixed $value

(string or int)

Returns

$this

getTotalSegments()

getTotalSegments() : integer

Returns the total number of segments.

Returns

integer

__toString()

__toString() 

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

createURIString()

createURIString(string  $scheme = null, string  $authority = null, string  $path = null, string  $query = null, string  $fragment = null) : string

Builds a representation of the string from the component parts.

Parameters

string $scheme
string $authority
string $path
string $query
string $fragment

Returns

string

setAuthority()

setAuthority(string  $str) : $this

Parses the given string an saves the appropriate authority pieces.

Parameters

string $str

Returns

$this

setScheme()

setScheme(  $str) : $this

Sets the scheme for this URI.

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

Parameters

$str

Returns

$this

setUserInfo()

setUserInfo(string  $user, string  $pass) : $this

Sets the userInfo/Authority portion of the URI.

Parameters

string $user

The user's username

string $pass

The user's password

Returns

$this

setHost()

setHost(string  $str) : $this

Sets the host name to use.

Parameters

string $str

Returns

$this

setPort()

setPort(integer  $port = null) : $this

Sets the port portion of the URI.

Parameters

integer $port

Returns

$this

setPath()

setPath(string  $path) : $this

Sets the path portion of the URI.

Parameters

string $path

Returns

$this

refreshPath()

refreshPath() : $this

Sets the path portion of the URI based on segments.

Returns

$this

setQuery()

setQuery(string  $query) : $this

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

Parameters

string $query

Returns

$this

setQueryArray()

setQueryArray(array  $query) : \CodeIgniter\HTTP\URI

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

Parameters

array $query

Returns

\CodeIgniter\HTTP\URI

addQuery()

addQuery(string  $key, mixed  $value = null) : $this

Adds a single new element to the query vars.

Parameters

string $key
mixed $value

Returns

$this

stripQuery()

stripQuery(array  ...$params) : $this

Removes one or more query vars from the URI.

Parameters

array $params variadic

Returns

$this

keepQuery()

keepQuery(array  ...$params) : $this

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

Parameters

array $params variadic

Returns

$this

setFragment()

setFragment(string  $string) : $this

Sets the fragment portion of the URI.

Parameters

string $string

Returns

$this

resolveRelativeURI()

resolveRelativeURI(string  $uri) : \CodeIgniter\HTTP\URI

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

Parameters

string $uri

Returns

\CodeIgniter\HTTP\URI

decode()

decode(string  $value) : string

Checks the value to see if it has been urlencoded and decodes it if so.

The urlencode check is not perfect but should catch most cases.

Parameters

string $value

Returns

string

splitQueryPart()

splitQueryPart(  $part) : array|null

Split a query value into it's key/value elements, if both are present.

Parameters

$part

Returns

array|null

filterPath()

filterPath(  $path = null) : string

Encodes any dangerous characters, and removes dot segments.

While dot segments have valid uses according to the spec, this URI class does not allow them.

Parameters

$path

Returns

string

applyParts()

applyParts(array  $parts) 

Saves our parts from a parse_url call.

Parameters

array $parts

mergePaths()

mergePaths(\CodeIgniter\HTTP\URI  $base, \CodeIgniter\HTTP\URI  $reference) : string

Given 2 paths, will merge them according to rules set out in RFC 2986, Section 5.2

Parameters

\CodeIgniter\HTTP\URI $base
\CodeIgniter\HTTP\URI $reference

Returns

string