Fr3nch13/CakePHP Utilities

Uri
in package
implements UriInterface, Stringable

Implementation of Psr\Http\UriInterface.

Provides a value object representing a URI for HTTP requests.

Instances of this class are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current instance and return a new instance that contains the changed state.

Tags
psalm-immutable

Table of Contents

Interfaces

UriInterface
Value object representing a URI.
Stringable

Constants

CHAR_SUB_DELIMS  = '!\$&\'\(\)\*\+,;='
Sub-delimiters used in user info, query strings and fragments.
CHAR_UNRESERVED  = 'a-zA-Z0-9_\-\.~\pL'
Unreserved characters used in user info, paths, query strings, and fragments.

Properties

$allowedSchemes  : array<string|int, int>
$fragment  : string
$host  : string
$path  : string
$port  : int|null
$query  : string
$scheme  : string
$uriString  : string|null
generated uri string cache
$userInfo  : string

Methods

__clone()  : mixed
Operations to perform on clone.
__construct()  : mixed
__toString()  : string
Return the string representation as a URI reference.
getAuthority()  : string
Retrieve the authority component of the URI.
getFragment()  : string
Retrieve the fragment component of the URI.
getHost()  : string
Retrieve the host component of the URI.
getPath()  : string
Retrieve the path component of the URI.
getPort()  : null|int
Retrieve the port component of the URI.
getQuery()  : string
Retrieve the query string of the URI.
getScheme()  : string
Retrieve the scheme component of the URI.
getUserInfo()  : string
Retrieve the user-info part of the URI.
withFragment()  : static
Return an instance with the specified URI fragment.
withHost()  : static
Return an instance with the specified host.
withPath()  : static
Return an instance with the specified path.
withPort()  : static
Return an instance with the specified port.
withQuery()  : static
Return an instance with the specified query string.
withScheme()  : static
Return an instance with the specified scheme.
withUserInfo()  : static
Create and return a new instance containing the provided user credentials.
createUriString()  : string
Create a URI string from its various parts
filterFragment()  : string
Filter a fragment value to ensure it is properly encoded.
filterInvalidUtf8()  : string
Encode invalid UTF-8 characters in given string. All other characters are unchanged.
filterPath()  : string
Filters the path of a URI to ensure it is properly encoded.
filterQuery()  : string
Filter a query string to ensure it is propertly encoded.
filterQueryOrFragment()  : string
Filter a query string key or value, or a fragment.
filterScheme()  : string
Filters the scheme to ensure it is a valid scheme.
filterUserInfoPart()  : string
Filters a part of user info in a URI to ensure it is properly encoded.
isNonStandardPort()  : bool
Is a given port non-standard for the current scheme?
parseUri()  : void
Parse a URI into its parts, and set the properties
splitQueryValue()  : array<string|int, mixed>
Split a query value into a key/value tuple.
urlEncodeChar()  : string
URL encode a character returned by a regex.

Constants

CHAR_SUB_DELIMS

Sub-delimiters used in user info, query strings and fragments.

public mixed CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;='
Tags
const

string

CHAR_UNRESERVED

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

public mixed CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~\pL'
Tags
const

string

Properties

$allowedSchemes

protected array<string|int, int> $allowedSchemes = ['http' => 80, 'https' => 443]

Array indexed by valid scheme names to their corresponding ports.

$fragment

private string $fragment = ''

$host

private string $host = ''

$path

private string $path = ''

$port

private int|null $port = null

$query

private string $query = ''

$scheme

private string $scheme = ''

$uriString

generated uri string cache

private string|null $uriString = null

$userInfo

private string $userInfo = ''

Methods

__clone()

Operations to perform on clone.

public __clone() : mixed

Since cloning usually is for purposes of mutation, we reset the $uriString property so it will be re-calculated.

__construct()

public __construct([string $uri = '' ]) : mixed
Parameters
$uri : string = ''

__toString()

Return the string representation as a URI reference.

public __toString() : string
Return values
string

getAuthority()

Retrieve the authority component of the URI.

public getAuthority() : string
Return values
string

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

getFragment()

Retrieve the fragment component of the URI.

public getFragment() : string
Return values
string

The URI fragment.

getHost()

Retrieve the host component of the URI.

public getHost() : string
Return values
string

The URI host.

getPath()

Retrieve the path component of the URI.

public getPath() : string
Return values
string

The URI path.

getPort()

Retrieve the port component of the URI.

public getPort() : null|int
Return values
null|int

The URI port.

getQuery()

Retrieve the query string of the URI.

public getQuery() : string
Return values
string

The URI query string.

getScheme()

Retrieve the scheme component of the URI.

public getScheme() : string
Return values
string

The URI scheme.

getUserInfo()

Retrieve the user-info part of the URI.

public getUserInfo() : string

This value is percent-encoded, per RFC 3986 Section 3.2.1.

Return values
string

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

withFragment()

Return an instance with the specified URI fragment.

public withFragment(mixed $fragment) : static
Parameters
$fragment : mixed

The fragment to use with the new instance.

Return values
static

A new instance with the specified fragment.

withHost()

Return an instance with the specified host.

public withHost(mixed $host) : static
Parameters
$host : mixed

The hostname to use with the new instance.

Return values
static

A new instance with the specified host.

withPath()

Return an instance with the specified path.

public withPath(mixed $path) : static
Parameters
$path : mixed

The path to use with the new instance.

Return values
static

A new instance with the specified path.

withPort()

Return an instance with the specified port.

public withPort(mixed $port) : static
Parameters
$port : mixed

The port to use with the new instance; a null value removes the port information.

Return values
static

A new instance with the specified port.

withQuery()

Return an instance with the specified query string.

public withQuery(mixed $query) : static
Parameters
$query : mixed

The query string to use with the new instance.

Return values
static

A new instance with the specified query string.

withScheme()

Return an instance with the specified scheme.

public withScheme(mixed $scheme) : static
Parameters
$scheme : mixed

The scheme to use with the new instance.

Return values
static

A new instance with the specified scheme.

withUserInfo()

Create and return a new instance containing the provided user credentials.

public withUserInfo(mixed $user[, mixed $password = null ]) : static

The value will be percent-encoded in the new instance, but with measures taken to prevent double-encoding.

Parameters
$user : mixed

The user name to use for authority.

$password : mixed = null

The password associated with $user.

Return values
static

A new instance with the specified user information.

createUriString()

Create a URI string from its various parts

private static createUriString(string $scheme, string $authority, string $path, string $query, string $fragment) : string
Parameters
$scheme : string
$authority : string
$path : string
$query : string
$fragment : string
Return values
string

filterFragment()

Filter a fragment value to ensure it is properly encoded.

private filterFragment(string $fragment) : string
Parameters
$fragment : string
Return values
string

filterInvalidUtf8()

Encode invalid UTF-8 characters in given string. All other characters are unchanged.

private filterInvalidUtf8(string $string) : string
Parameters
$string : string
Return values
string

filterPath()

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

private filterPath(string $path) : string
Parameters
$path : string
Return values
string

filterQuery()

Filter a query string to ensure it is propertly encoded.

private filterQuery(string $query) : string

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

Parameters
$query : string
Return values
string

filterQueryOrFragment()

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

private filterQueryOrFragment(string $value) : string
Parameters
$value : string
Return values
string

filterScheme()

Filters the scheme to ensure it is a valid scheme.

private filterScheme(string $scheme) : string
Parameters
$scheme : string

Scheme name.

Return values
string

Filtered scheme.

filterUserInfoPart()

Filters a part of user info in a URI to ensure it is properly encoded.

private filterUserInfoPart(string $part) : string
Parameters
$part : string
Return values
string

isNonStandardPort()

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

private isNonStandardPort(string $scheme, string $host, int|null $port) : bool
Parameters
$scheme : string
$host : string
$port : int|null
Return values
bool

parseUri()

Parse a URI into its parts, and set the properties

private parseUri(string $uri) : void
Parameters
$uri : string
Tags
psalm-suppress

InaccessibleProperty Method is only called in Uri::__construct and thus immutability is still given.

splitQueryValue()

Split a query value into a key/value tuple.

private splitQueryValue(string $value) : array<string|int, mixed>
Parameters
$value : string
Return values
array<string|int, mixed>

A value with exactly two elements, key and value

urlEncodeChar()

URL encode a character returned by a regex.

private urlEncodeChar(array<string|int, mixed> $matches) : string
Parameters
$matches : array<string|int, mixed>
Return values
string

        
On this page

Search results