class Uri implements Htmlable, Responsable (View source)

Traits

Properties

protected $uri

The URI instance.

static protected $urlGeneratorResolver

The URL generator resolver.

Methods

$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

tap($callback = null)

Call the given Closure with this instance then return the instance.

from  Tappable
__construct(UriInterface|Stringable|string $uri = '')

Create a new parsed URI instance.

static Uri
of(UriInterface|Stringable|string $uri = '')

Create a new URI instance.

static Uri
to(string $path)

Get a URI instance of an absolute URL for the given path.

static Uri
route(BackedEnum|string $name, mixed $parameters = [], bool $absolute = true)

Get a URI instance for a named route.

string|null
scheme()

Get the URI's scheme.

string|null
user(bool $withPassword = false)

Get the user from the URI.

string|null
password()

Get the password from the URI.

string|null
host()

Get the URI's host.

int|null
port()

Get the URI's port.

string|null
path()

Get the URI's path.

query()

Get the URI's query string.

string|null
fragment()

Get the URI's fragment.

Uri
withScheme(Stringable|string $scheme)

Specify the scheme of the URI.

Uri
withUser(Stringable|string|null $user, Stringable|string|null $password = null)

Specify the user and password for the URI.

Uri
withHost(Stringable|string $host)

Specify the host of the URI.

Uri
withPort(int|null $port)

Specify the port of the URI.

Uri
withPath(Stringable|string $path)

Specify the path of the URI.

Uri
withQuery(array $query, bool $merge = true)

Merge new query parameters into the URI.

Uri
withQueryIfMissing(array $query)

Merge new query parameters into the URI if they are not already in the query string.

Uri
pushOntoQuery(string $key, mixed $value)

Push a value onto the end of a query string parameter that is a list.

Uri
withoutQuery(array $keys)

Remove the given query parameters from the URI.

Uri
replaceQuery(array $query)

Specify new query parameters for the URI.

Uri
withFragment(string $fragment)

Specify the fragment of the URI.

redirect(int $status = 302, array $headers = [])

Create a redirect HTTP response for the given URI.

Response
toResponse(Request $request)

Create an HTTP response that represents the object.

string
toHtml()

Get content as a string of HTML.

string
decode()

Get the decoded string representation of the URI.

string
value()

Get the string representation of the URI.

bool
isEmpty()

Determine if the URI is currently an empty string.

static void
setUrlGeneratorResolver(Closure $urlGeneratorResolver)

Set the URL generator resolver.

UriInterface
getUri()

Get the underlying URI instance.

string
__toString()

Get the string representation of the URI.

Details

$this|TWhenReturnType when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TUnlessReturnType

tap($callback = null)

Call the given Closure with this instance then return the instance.

Parameters

$callback

__construct(UriInterface|Stringable|string $uri = '')

Create a new parsed URI instance.

Parameters

UriInterface|Stringable|string $uri

static Uri of(UriInterface|Stringable|string $uri = '')

Create a new URI instance.

Parameters

UriInterface|Stringable|string $uri

Return Value

Uri

static Uri to(string $path)

Get a URI instance of an absolute URL for the given path.

Parameters

string $path

Return Value

Uri

static Uri route(BackedEnum|string $name, mixed $parameters = [], bool $absolute = true)

Get a URI instance for a named route.

Parameters

BackedEnum|string $name
mixed $parameters
bool $absolute

Return Value

Uri

Exceptions

InvalidArgumentException

string|null scheme()

Get the URI's scheme.

Return Value

string|null

string|null user(bool $withPassword = false)

Get the user from the URI.

Parameters

bool $withPassword

Return Value

string|null

string|null password()

Get the password from the URI.

Return Value

string|null

string|null host()

Get the URI's host.

Return Value

string|null

int|null port()

Get the URI's port.

Return Value

int|null

string|null path()

Get the URI's path.

Empty or missing paths are returned as a single "/".

Return Value

string|null

UriQueryString query()

Get the URI's query string.

Return Value

UriQueryString

string|null fragment()

Get the URI's fragment.

Return Value

string|null

Uri withScheme(Stringable|string $scheme)

Specify the scheme of the URI.

Parameters

Stringable|string $scheme

Return Value

Uri

Uri withUser(Stringable|string|null $user, Stringable|string|null $password = null)

Specify the user and password for the URI.

Parameters

Stringable|string|null $user
Stringable|string|null $password

Return Value

Uri

Uri withHost(Stringable|string $host)

Specify the host of the URI.

Parameters

Stringable|string $host

Return Value

Uri

Uri withPort(int|null $port)

Specify the port of the URI.

Parameters

int|null $port

Return Value

Uri

Uri withPath(Stringable|string $path)

Specify the path of the URI.

Parameters

Stringable|string $path

Return Value

Uri

Uri withQuery(array $query, bool $merge = true)

Merge new query parameters into the URI.

Parameters

array $query
bool $merge

Return Value

Uri

Uri withQueryIfMissing(array $query)

Merge new query parameters into the URI if they are not already in the query string.

Parameters

array $query

Return Value

Uri

Uri pushOntoQuery(string $key, mixed $value)

Push a value onto the end of a query string parameter that is a list.

Parameters

string $key
mixed $value

Return Value

Uri

Uri withoutQuery(array $keys)

Remove the given query parameters from the URI.

Parameters

array $keys

Return Value

Uri

Uri replaceQuery(array $query)

Specify new query parameters for the URI.

Parameters

array $query

Return Value

Uri

Uri withFragment(string $fragment)

Specify the fragment of the URI.

Parameters

string $fragment

Return Value

Uri

RedirectResponse redirect(int $status = 302, array $headers = [])

Create a redirect HTTP response for the given URI.

Parameters

int $status
array $headers

Return Value

RedirectResponse

Response toResponse(Request $request)

Create an HTTP response that represents the object.

Parameters

Request $request

Return Value

Response

string toHtml()

Get content as a string of HTML.

Return Value

string

string decode()

Get the decoded string representation of the URI.

Return Value

string

string value()

Get the string representation of the URI.

Return Value

string

bool isEmpty()

Determine if the URI is currently an empty string.

Return Value

bool

static void setUrlGeneratorResolver(Closure $urlGeneratorResolver)

Set the URL generator resolver.

Parameters

Closure $urlGeneratorResolver

Return Value

void

UriInterface getUri()

Get the underlying URI instance.

Return Value

UriInterface

string __toString()

Get the string representation of the URI.

Return Value

string