Documentation

Http
in package
implements Stringable, UriInterface, JsonSerializable, Conditionable

FinalYes
Tags
phpstan-import-type

InputComponentMap from UriString

Table of Contents

Interfaces

Stringable
UriInterface
Value object representing a URI.
JsonSerializable
Conditionable

Properties

$uri  : UriInterface

Methods

__toString()  : string
createFromBaseUri()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
createFromComponents()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
createFromServer()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
createFromString()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
createFromUri()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
fromBaseUri()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
fromComponents()  : self
Create a new instance from a hash of parse_url parts.
fromServer()  : self
Create a new instance from the environment.
fromTemplate()  : self
Creates a new instance from a template.
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 information component of the URI.
jsonSerialize()  : string
new()  : self
Create a new instance from a string or a stringable object.
parse()  : self|null
Returns a new instance from a URI and a Base URI.or null on failure.
tryNew()  : self|null
Create a new instance from a string or a stringable structure or returns null on failure.
when()  : static
Apply the callback if the given "condition" is (or resolves to) true.
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
Return an instance with the specified user information.
__construct()  : mixed
filterInput()  : string|null
Safely stringify input when possible for League UriInterface compatibility.
newInstance()  : self
normalizePsr7Uri()  : UriInterface
PSR-7 UriInterface makes the following normalization.

Properties

Methods

__toString()

public __toString() : string
Return values
string

createFromBaseUri()

DEPRECATION WARNING! This method will be removed in the next major point release.

public static createFromBaseUri(Stringable|string $uri[, Stringable|string|null $baseUri = null ]) : self

Since version 7.0.0

use League\Uri\Http::fromBaseUri() instead

Parameters
$uri : Stringable|string
$baseUri : Stringable|string|null = null
Tags
codeCoverageIgnore
see
Http::fromBaseUri()

Create a new instance from a URI and a Base URI.

The returned URI must be absolute.

Return values
self

createFromComponents()

DEPRECATION WARNING! This method will be removed in the next major point release.

public static createFromComponents(InputComponentMap $components) : self

Since version 7.0.0

use League\Uri\Http::fromComponents() instead

Parameters
$components : InputComponentMap

a hash representation of the URI similar to PHP parse_url function result

Tags
codeCoverageIgnore
see
Http::fromComponents()

Create a new instance from a hash of parse_url parts.

Return values
self

createFromServer()

DEPRECATION WARNING! This method will be removed in the next major point release.

public static createFromServer(array<string|int, mixed> $server) : self

Since version 7.0.0

use League\Uri\Http::fromServer() instead

Parameters
$server : array<string|int, mixed>
Tags
codeCoverageIgnore
see
Http::fromServer()

Create a new instance from the environment.

Return values
self

createFromString()

DEPRECATION WARNING! This method will be removed in the next major point release.

public static createFromString([Stringable|string $uri = '' ]) : self

Since version 7.0.0

use League\Uri\Http::new() instead

Parameters
$uri : Stringable|string = ''
Tags
codeCoverageIgnore
see
Http::new()

Create a new instance from a string.

Return values
self

createFromUri()

DEPRECATION WARNING! This method will be removed in the next major point release.

public static createFromUri(UriInterface|UriInterface $uri) : self

Since version 7.0.0

use League\Uri\Http::new() instead

Parameters
$uri : UriInterface|UriInterface
Tags
codeCoverageIgnore
see
Http::new()

Create a new instance from a URI object.

Return values
self

fromBaseUri()

DEPRECATION WARNING! This method will be removed in the next major point release.

public static fromBaseUri(Uri|Url|Stringable|string $uri[, Uri|Url|Stringable|string|null $baseUri = null ]) : self

Since version 7.6.0

use League\Uri\Http::parse() instead

Parameters
$uri : Uri|Url|Stringable|string
$baseUri : Uri|Url|Stringable|string|null = null
Tags
codeCoverageIgnore
see
Http::parse()

Create a new instance from a URI and a Base URI.

The returned URI must be absolute.

Return values
self

fromComponents()

Create a new instance from a hash of parse_url parts.

public static fromComponents(InputComponentMap $components) : self
Parameters
$components : InputComponentMap

a hash representation of the URI similar to PHP parse_url function result

Return values
self

fromServer()

Create a new instance from the environment.

public static fromServer(array<string|int, mixed> $server) : self
Parameters
$server : array<string|int, mixed>
Return values
self

fromTemplate()

Creates a new instance from a template.

public static fromTemplate(Stringable|string $template[, iterable<string|int, mixed> $variables = [] ]) : self
Parameters
$template : Stringable|string
$variables : iterable<string|int, mixed> = []
Tags
throws
TemplateCanNotBeExpanded

if the variables are invalid or missing

throws
UriException

if the variables are invalid or missing

Return values
self

getAuthority()

Retrieve the authority component of the URI.

public getAuthority() : string

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.

Return values
string

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

getFragment()

Retrieve the fragment component of the URI.

public getFragment() : string

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.

Return values
string

The URI fragment.

getHost()

Retrieve the host component of the URI.

public getHost() : string

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.

Return values
string

The URI host.

getPath()

Retrieve the path component of the URI.

public getPath() : string

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.

Return values
string

The URI path.

getPort()

Retrieve the port component of the URI.

public getPort() : null|int

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.

Return values
null|int

The URI port.

getQuery()

Retrieve the query string of the URI.

public getQuery() : string

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.

Return values
string

The URI query string.

getScheme()

Retrieve the scheme component of the URI.

public getScheme() : string

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.

Return values
string

The URI scheme.

getUserInfo()

Retrieve the user information component of the URI.

public getUserInfo() : string

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.

Return values
string

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

jsonSerialize()

public jsonSerialize() : string
Return values
string

new()

Create a new instance from a string or a stringable object.

public static new([Uri|Url|Stringable|string $uri = '' ]) : self
Parameters
$uri : Uri|Url|Stringable|string = ''
Return values
self

parse()

Returns a new instance from a URI and a Base URI.or null on failure.

public static parse(Url|Uri|Stringable|string $uri[, Url|Uri|Stringable|string|null $baseUri = null ]) : self|null

The returned URI must be absolute if a base URI is provided

Parameters
$uri : Url|Uri|Stringable|string
$baseUri : Url|Uri|Stringable|string|null = null
Return values
self|null

tryNew()

Create a new instance from a string or a stringable structure or returns null on failure.

public static tryNew([Uri|Url|Stringable|string $uri = '' ]) : self|null
Parameters
$uri : Uri|Url|Stringable|string = ''
Return values
self|null

when()

Apply the callback if the given "condition" is (or resolves to) true.

public when(callable|bool $condition, callable $onSuccess[, callable|null $onFail = null ]) : static
Parameters
$condition : callable|bool
$onSuccess : callable
$onFail : callable|null = null
Return values
static

withFragment()

Return an instance with the specified URI fragment.

public withFragment(string $fragment) : static

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
$fragment : string

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(string $host) : static

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
$host : string

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(string $path) : static

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
$path : string

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(int|null $port) : static

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
$port : int|null

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(string $query) : static

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
$query : string

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(string $scheme) : static

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
$scheme : string

The scheme to use with the new instance.

Return values
static

A new instance with the specified scheme.

withUserInfo()

Return an instance with the specified user information.

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

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
$user : string

The user name to use for authority.

$password : string|null = null

The password associated with $user.

Return values
static

A new instance with the specified user information.

filterInput()

Safely stringify input when possible for League UriInterface compatibility.

private filterInput(string $str) : string|null
Parameters
$str : string
Return values
string|null

normalizePsr7Uri()

PSR-7 UriInterface makes the following normalization.

private normalizePsr7Uri(UriInterface $uri) : UriInterface

Safely stringify input when possible for League UriInterface compatibility.

Query, Fragment and User Info when undefined are normalized to the empty string

Parameters
$uri : UriInterface
Return values
UriInterface

        
On this page

Search results