‪TYPO3CMS  11.5
TYPO3\CMS\Core\Http\Uri Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\Uri:

Public Member Functions

 __construct ($uri='')
 
string getScheme ()
 
string getAuthority ()
 
string getUserInfo ()
 
string getHost ()
 
int null getPort ()
 
string getPath ()
 
string getQuery ()
 
string getFragment ()
 
string __toString ()
 

Static Public Member Functions

static withScheme ($scheme)
 
static withUserInfo ($user, $password=null)
 
static withHost ($host)
 
static withPort ($port)
 
static withPath ($path)
 
static withQuery ($query)
 
static withFragment ($fragment)
 

Public Attributes

const SUBDELIMITER_CHARLIST = '!\$&\'\‍(\‍)\*\+,;='
 
const UNRESERVED_CHARLIST = 'a-zA-Z0-9_\-\.~'
 

Protected Member Functions

 parseUri ($uri)
 
bool isNonStandardPort ($scheme, $host, $port)
 
string sanitizeScheme ($scheme)
 
string sanitizePath ($path)
 
string sanitizeQuery ($query)
 
array splitQueryValue ($value)
 
string sanitizeFragment ($fragment)
 
string sanitizeQueryOrFragment ($value)
 

Protected Attributes

string $scheme = ''
 
int[] $supportedSchemes
 
string $authority = ''
 
string $userInfo = ''
 
string $host = ''
 
int null $port
 
string $path = ''
 
string $query = ''
 
string $fragment
 

Detailed Description

Represents a URI based on the PSR-7 Standard.

Highly inspired by https://github.com/phly/http/

Note that this is not public API yet.

Definition at line 28 of file Uri.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Http\Uri::__construct (   $uri = '')
Parameters
string | null$uri‪The full URI including query string and fragment
Exceptions

Definition at line 95 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\parseUri().

Member Function Documentation

◆ __toString()

string TYPO3\CMS\Core\Http\Uri::__toString ( )

Return the string representation as a URI reference.

Depending on which components of the URI are present, the resulting string is either a full URI or relative reference according to RFC 3986, Section 4.1. The method concatenates the various components of the URI, using the appropriate delimiters:

  • ‪If a scheme is present, it MUST be suffixed by ":".
  • ‪If an authority is present, it MUST be prefixed by "//".
  • ‪The path can be concatenated without delimiters. But there are two cases where the path has to be adjusted to make the URI reference valid as PHP does not allow to throw an exception in __toString():
    • ‪If the path is rootless and an authority is present, the path MUST be prefixed by "/".
    • ‪If the path is starting with more than one "/" and no authority is present, the starting slashes MUST be reduced to one.
  • ‪If a query is present, it MUST be prefixed by "?".
  • ‪If a fragment is present, it MUST be prefixed by "#".
See also
https://tools.ietf.org/html/rfc3986#section-4.1
Returns
‪string

Definition at line 568 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$authority, TYPO3\CMS\Core\Http\Uri\$fragment, TYPO3\CMS\Core\Http\Uri\$path, TYPO3\CMS\Core\Http\Uri\$query, TYPO3\CMS\Core\Http\Uri\getAuthority(), and TYPO3\CMS\Core\Http\Uri\getPath().

◆ getAuthority()

string TYPO3\CMS\Core\Http\Uri::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.

See also
https://tools.ietf.org/html/rfc3986#section-3.2
Returns
‪string The URI authority, in "[user-info@]host[:port]" format.

Definition at line 188 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$authority, TYPO3\CMS\Core\Http\Uri\$host, TYPO3\CMS\Core\Http\Uri\$port, and TYPO3\CMS\Core\Http\Uri\isNonStandardPort().

Referenced by TYPO3\CMS\Core\Http\Uri\__toString().

◆ getFragment()

string TYPO3\CMS\Core\Http\Uri::getFragment ( )

Retrieve the fragment component of the URI.

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

The leading "#" character is not part of the fragment and MUST NOT be added.

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.5.

See also
https://tools.ietf.org/html/rfc3986#section-2
https://tools.ietf.org/html/rfc3986#section-3.5
Returns
‪string The URI fragment.

Definition at line 333 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$fragment.

◆ getHost()

string TYPO3\CMS\Core\Http\Uri::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.

See also
https://tools.ietf.org/html/rfc3986#section-3.2.2
Returns
‪string The URI host.

Definition at line 237 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$host.

Referenced by TYPO3\CMS\Redirects\Service\IntegrityService\getMatchingRedirectByUri().

◆ getPath()

string TYPO3\CMS\Core\Http\Uri::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.

See also
https://tools.ietf.org/html/rfc3986#section-2
https://tools.ietf.org/html/rfc3986#section-3.3
Returns
‪string The URI path.

Definition at line 287 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$path.

Referenced by TYPO3\CMS\Core\Http\Uri\__toString(), and TYPO3\CMS\Redirects\Service\IntegrityService\getMatchingRedirectByUri().

◆ getPort()

int null TYPO3\CMS\Core\Http\Uri::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
‪int|null The URI port.

Definition at line 257 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\isNonStandardPort().

Referenced by TYPO3\CMS\Redirects\Service\IntegrityService\getMatchingRedirectByUri().

◆ getQuery()

string TYPO3\CMS\Core\Http\Uri::getQuery ( )

Retrieve the query string of the URI.

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

The leading "?" character is not part of the query and MUST NOT be added.

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.4.

As an example, if a value in a key/value pair of the query string should include an ampersand ("&") not intended as a delimiter between values, that value MUST be passed in encoded form (e.g., "%26") to the instance.

See also
https://tools.ietf.org/html/rfc3986#section-2
https://tools.ietf.org/html/rfc3986#section-3.4
Returns
‪string The URI query string.

Definition at line 312 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$query.

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\addQueryParams().

◆ getScheme()

string TYPO3\CMS\Core\Http\Uri::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.

See also
https://tools.ietf.org/html/rfc3986#section-3.1
Returns
‪string The URI scheme.

Definition at line 165 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$scheme.

◆ getUserInfo()

string TYPO3\CMS\Core\Http\Uri::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.

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

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

Definition at line 221 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$userInfo.

◆ isNonStandardPort()

bool TYPO3\CMS\Core\Http\Uri::isNonStandardPort (   $scheme,
  $host,
  $port 
)
protected

Is a given port non-standard for the current scheme?

Parameters
string$scheme
string$host
int | null$port
Returns
‪bool

Definition at line 604 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$host, TYPO3\CMS\Core\Http\Uri\$port, and TYPO3\CMS\Core\Http\Uri\$scheme.

Referenced by TYPO3\CMS\Core\Http\Uri\getAuthority(), and TYPO3\CMS\Core\Http\Uri\getPort().

◆ parseUri()

TYPO3\CMS\Core\Http\Uri::parseUri (   $uri)
protected

helper function for parsing the full URI string

Parameters
string$uri
Exceptions

Definition at line 111 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\sanitizeFragment(), TYPO3\CMS\Core\Http\Uri\sanitizePath(), TYPO3\CMS\Core\Http\Uri\sanitizeQuery(), and TYPO3\CMS\Core\Http\Uri\sanitizeScheme().

Referenced by TYPO3\CMS\Core\Http\Uri\__construct().

◆ sanitizeFragment()

string TYPO3\CMS\Core\Http\Uri::sanitizeFragment (   $fragment)
protected

Filter a fragment value to ensure it is properly encoded.

Parameters
string | null$fragment
Returns
‪string

Definition at line 706 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$fragment, and TYPO3\CMS\Core\Http\Uri\sanitizeQueryOrFragment().

Referenced by TYPO3\CMS\Core\Http\Uri\parseUri(), and TYPO3\CMS\Core\Http\Uri\withFragment().

◆ sanitizePath()

string TYPO3\CMS\Core\Http\Uri::sanitizePath (   $path)
protected

Filters the path of a URI to ensure it is properly encoded.

Parameters
string$path
Returns
‪string

Definition at line 647 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$path.

Referenced by TYPO3\CMS\Core\Http\Uri\parseUri(), and TYPO3\CMS\Core\Http\Uri\withPath().

◆ sanitizeQuery()

string TYPO3\CMS\Core\Http\Uri::sanitizeQuery (   $query)
protected

Filter a query string to ensure it is properly encoded.

Ensures that the values in the query string are properly urlencoded.

Parameters
string$query
Returns
‪string

Definition at line 666 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$query, TYPO3\CMS\Core\Http\Uri\sanitizeQueryOrFragment(), and TYPO3\CMS\Core\Http\Uri\splitQueryValue().

Referenced by TYPO3\CMS\Core\Http\Uri\parseUri(), and TYPO3\CMS\Core\Http\Uri\withQuery().

◆ sanitizeQueryOrFragment()

string TYPO3\CMS\Core\Http\Uri::sanitizeQueryOrFragment (   $value)
protected

Filter a query string key or value, or a fragment.

Parameters
string$value
Returns
‪string

Definition at line 725 of file Uri.php.

Referenced by TYPO3\CMS\Core\Http\Uri\sanitizeFragment(), and TYPO3\CMS\Core\Http\Uri\sanitizeQuery().

◆ sanitizeScheme()

string TYPO3\CMS\Core\Http\Uri::sanitizeScheme (   $scheme)
protected

Filters the scheme to ensure it is a valid scheme.

Parameters
string$scheme‪Scheme name.
Returns
‪string Filtered scheme.
Exceptions

Definition at line 625 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$scheme.

Referenced by TYPO3\CMS\Core\Http\Uri\parseUri(), and TYPO3\CMS\Core\Http\Uri\withScheme().

◆ splitQueryValue()

array TYPO3\CMS\Core\Http\Uri::splitQueryValue (   $value)
protected

Split a query value into a key/value tuple.

Parameters
string$value
Returns
‪array A value with exactly two elements, key and value

Definition at line 691 of file Uri.php.

Referenced by TYPO3\CMS\Core\Http\Uri\sanitizeQuery().

◆ withFragment()

static TYPO3\CMS\Core\Http\Uri::withFragment (   $fragment)
static

Return an instance with the specified URI fragment.

This method MUST retain the state of the current instance, and return an instance that contains the specified URI fragment.

Users can provide both encoded and decoded fragment characters. Implementations ensure the correct encoding as outlined in getFragment().

An empty fragment value is equivalent to removing the fragment.

Parameters
string$fragment‪The fragment to use with the new instance.
Returns
‪static A new instance with the specified fragment.

Definition at line 537 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$fragment, and TYPO3\CMS\Core\Http\Uri\sanitizeFragment().

◆ withHost()

static TYPO3\CMS\Core\Http\Uri::withHost (   $host)
static

Return an instance with the specified host.

This method MUST retain the state of the current instance, and return an instance that contains the specified host.

An empty host value is equivalent to removing the host.

Parameters
string$host‪The hostname to use with the new instance.
Returns
‪static A new instance with the specified host.
Exceptions

Definition at line 403 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$host.

◆ withPath()

static TYPO3\CMS\Core\Http\Uri::withPath (   $path)
static

Return an instance with the specified path.

This method MUST retain the state of the current instance, and return an instance that contains the specified path.

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.

If the path is intended to be domain-relative rather than path relative then it must begin with a slash ("/"). Paths not starting with a slash ("/") are assumed to be relative to some base path known to the application or consumer.

Users can provide both encoded and decoded path characters. Implementations ensure the correct encoding as outlined in getPath().

Parameters
string$path‪The path to use with the new instance.
Returns
‪static A new instance with the specified path.
Exceptions

Definition at line 470 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$path, and TYPO3\CMS\Core\Http\Uri\sanitizePath().

◆ withPort()

static TYPO3\CMS\Core\Http\Uri::withPort (   $port)
static

Return an instance with the specified port.

This method MUST retain the state of the current instance, and return an instance that contains the specified port.

Implementations MUST raise an exception for ports outside the established TCP and UDP port ranges.

A null value provided for the port is equivalent to removing the port information.

Parameters
int | null$port‪The port to use with the new instance; a null value removes the port information.
Returns
‪static A new instance with the specified port.
Exceptions

Definition at line 428 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$port, and TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger().

◆ withQuery()

static TYPO3\CMS\Core\Http\Uri::withQuery (   $query)
static

Return an instance with the specified query string.

This method MUST retain the state of the current instance, and return an instance that contains the specified query string.

Users can provide both encoded and decoded query characters. Implementations ensure the correct encoding as outlined in getQuery().

An empty query string value is equivalent to removing the query string.

Parameters
string$query‪The query string to use with the new instance.
Returns
‪static A new instance with the specified query string.
Exceptions

Definition at line 506 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$query, and TYPO3\CMS\Core\Http\Uri\sanitizeQuery().

Referenced by TYPO3\CMS\Redirects\Service\RedirectService\addQueryParams().

◆ withScheme()

static TYPO3\CMS\Core\Http\Uri::withScheme (   $scheme)
static

Return an instance with the specified scheme.

This method MUST retain the state of the current instance, and return an instance that contains the specified scheme.

Implementations MUST support the schemes "http" and "https" case insensitively, and MAY accommodate other schemes if required.

An empty scheme is equivalent to removing the scheme.

Parameters
string$scheme‪The scheme to use with the new instance.
Returns
‪static A new instance with the specified scheme.
Exceptions

Definition at line 354 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$scheme, and TYPO3\CMS\Core\Http\Uri\sanitizeScheme().

◆ withUserInfo()

static TYPO3\CMS\Core\Http\Uri::withUserInfo (   $user,
  $password = null 
)
static

Return an instance with the specified user information.

This method MUST retain the state of the current instance, and return an instance that contains the specified user information.

Password is optional, but the user information MUST include the user; an empty string for the user is equivalent to removing user information.

Parameters
string$user‪The user name to use for authority.
string | null$password‪The password associated with $user.
Returns
‪static A new instance with the specified user information.

Definition at line 378 of file Uri.php.

References TYPO3\CMS\Core\Http\Uri\$userInfo.

Member Data Documentation

◆ $authority

string TYPO3\CMS\Core\Http\Uri::$authority = ''
protected

The authority part of the URI

Definition at line 59 of file Uri.php.

Referenced by TYPO3\CMS\Core\Http\Uri\__toString(), and TYPO3\CMS\Core\Http\Uri\getAuthority().

◆ $fragment

string TYPO3\CMS\Core\Http\Uri::$fragment
protected

◆ $host

string TYPO3\CMS\Core\Http\Uri::$host = ''
protected

◆ $path

string TYPO3\CMS\Core\Http\Uri::$path = ''
protected

The path part of the URI (can be empty or /)

Definition at line 79 of file Uri.php.

Referenced by TYPO3\CMS\Core\Http\Uri\__toString(), TYPO3\CMS\Core\Http\Uri\getPath(), TYPO3\CMS\Core\Http\Uri\sanitizePath(), and TYPO3\CMS\Core\Http\Uri\withPath().

◆ $port

int null TYPO3\CMS\Core\Http\Uri::$port
protected

The port of the URI (empty if it is the standard port for the scheme)

Definition at line 74 of file Uri.php.

Referenced by TYPO3\CMS\Core\Http\Uri\getAuthority(), TYPO3\CMS\Core\Http\Uri\isNonStandardPort(), and TYPO3\CMS\Core\Http\Uri\withPort().

◆ $query

string TYPO3\CMS\Core\Http\Uri::$query = ''
protected

◆ $scheme

string TYPO3\CMS\Core\Http\Uri::$scheme = ''
protected

◆ $supportedSchemes

int [] TYPO3\CMS\Core\Http\Uri::$supportedSchemes
protected
Initial value:
= array(
'http' => 80,
'https' => 443,
)

Associative array containing schemes and their default ports.

Definition at line 51 of file Uri.php.

◆ $userInfo

string TYPO3\CMS\Core\Http\Uri::$userInfo = ''
protected

The userInfo part of the URI

Definition at line 64 of file Uri.php.

Referenced by TYPO3\CMS\Core\Http\Uri\getUserInfo(), and TYPO3\CMS\Core\Http\Uri\withUserInfo().

◆ SUBDELIMITER_CHARLIST

const TYPO3\CMS\Core\Http\Uri::SUBDELIMITER_CHARLIST = '!\$&\'\‍(\‍)\*\+,;='

Definition at line 35 of file Uri.php.

◆ UNRESERVED_CHARLIST

const TYPO3\CMS\Core\Http\Uri::UNRESERVED_CHARLIST = 'a-zA-Z0-9_\-\.~'

Definition at line 42 of file Uri.php.