class Uri implements Htmlable, JsonSerializable, Responsable, Stringable

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected UriInterface $uri

The URI instance.

static protected Closure|null $urlGeneratorResolver

The URL generator resolver.

Methods

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

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

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

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

never
dd(mixed ...$args)

Dump the given arguments and terminate execution.

from  Dumpable
Uri
dump(mixed ...$args)

Dump the string representation of the URI.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
tap(callable|null $callback = null)

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

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

Create a new parsed URI instance.

static Uri
of(string|Stringable|UriInterface $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, array $parameters = [], bool $absolute = true)

Get a URI instance for a named route.

static Uri
signedRoute(BackedEnum|string $name, array $parameters = [], DateInterval|DateTimeInterface|int|null $expiration = null, bool $absolute = true)

Create a signed route URI instance for a named route.

static Uri
temporarySignedRoute(BackedEnum|string $name, DateInterval|DateTimeInterface|int|null $expiration = null, array $parameters = [], bool $absolute = true)

Create a temporary signed route URI instance for a named route.

static Uri
action(array|string $action, array $parameters = [], bool $absolute = true)

Get a URI instance for a controller action.

string|null
authority()

Get the URI's authority.

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
path()

Get the URI's path.

pathSegments()

Get the URI's path segments.

query()

Get the URI's query string.

string|null
fragment()

Get the URI's fragment.

Uri
withScheme(string|Stringable $scheme)

Specify the scheme of the URI.

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

Specify the user and password for the URI.

Uri
withHost(string|Stringable $host)

Specify the host of the URI.

Uri
withPort(int|null $port)

Specify the port of the URI.

Uri
withPath(string|Stringable $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|string $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.

Uri
withoutFragment()

Remove the fragment from the URI.

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

Create a redirect HTTP response for the given URI.

toStringable()

Get the URI as a Stringable instance.

Response
toResponse(Request $request)

Create an HTTP response that represents the URI object.

string
toHtml()

Get the URI as a string of HTML.

string
decode()

Get the decoded string representation of the URI.

string
value()

Get the string representation of the URI.

string
toString()

Get the string representation of the URI.

bool
isEmpty()

Determine if the URI is currently an empty string.

bool
isNotEmpty()

Determine if the URI is not an empty string.

static void
setUrlGeneratorResolver(Closure $urlGeneratorResolver)

Set the URL generator resolver.

UriInterface
getUri()

Get the underlying URI instance.

string
jsonSerialize()

Convert the object into a value that is JSON serializable.

string
__toString()

Get the string representation of the URI.

static void
flushState()

Flush all static state.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

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

Parameters

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

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

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

Parameters

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

Return Value

mixed

in Dumpable at line 12
never dd(mixed ...$args)

Dump the given arguments and terminate execution.

Parameters

mixed ...$args

Return Value

never

at line 411
Uri dump(mixed ...$args)

Dump the string representation of the URI.

Parameters

mixed ...$args

Return Value

Uri

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Tappable at line 15
mixed tap(callable|null $callback = null)

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

Parameters

callable|null $callback

Return Value

mixed

at line 46
__construct(string|Stringable|UriInterface $uri = '')

Create a new parsed URI instance.

Parameters

string|Stringable|UriInterface $uri

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

Create a new URI instance.

Parameters

string|Stringable|UriInterface $uri

Return Value

Uri

at line 62
static Uri to(string $path)

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

Parameters

string $path

Return Value

Uri

at line 72
static Uri route(BackedEnum|string $name, array $parameters = [], bool $absolute = true)

Get a URI instance for a named route.

Parameters

BackedEnum|string $name
array $parameters
bool $absolute

Return Value

Uri

Exceptions

InvalidArgumentException

at line 82
static Uri signedRoute(BackedEnum|string $name, array $parameters = [], DateInterval|DateTimeInterface|int|null $expiration = null, bool $absolute = true)

Create a signed route URI instance for a named route.

Parameters

BackedEnum|string $name
array $parameters
DateInterval|DateTimeInterface|int|null $expiration
bool $absolute

Return Value

Uri

Exceptions

InvalidArgumentException

at line 90
static Uri temporarySignedRoute(BackedEnum|string $name, DateInterval|DateTimeInterface|int|null $expiration = null, array $parameters = [], bool $absolute = true)

Create a temporary signed route URI instance for a named route.

Parameters

BackedEnum|string $name
DateInterval|DateTimeInterface|int|null $expiration
array $parameters
bool $absolute

Return Value

Uri

at line 100
static Uri action(array|string $action, array $parameters = [], bool $absolute = true)

Get a URI instance for a controller action.

Parameters

array|string $action
array $parameters
bool $absolute

Return Value

Uri

Exceptions

InvalidArgumentException

at line 108
string|null authority()

Get the URI's authority.

Return Value

string|null

at line 116
string|null scheme()

Get the URI's scheme.

Return Value

string|null

at line 124
string|null user(bool $withPassword = false)

Get the user from the URI.

Parameters

bool $withPassword

Return Value

string|null

at line 134
string|null password()

Get the password from the URI.

Return Value

string|null

at line 142
string|null host()

Get the URI's host.

Return Value

string|null

at line 150
int|null port()

Get the URI's port.

Return Value

int|null

at line 162
string path()

Get the URI's path.

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

Return Value

string

at line 174
Collection pathSegments()

Get the URI's path segments.

Empty or missing paths are returned as an empty collection.

Return Value

Collection

at line 184
UriQueryString query()

Get the URI's query string.

Return Value

UriQueryString

at line 192
string|null fragment()

Get the URI's fragment.

Return Value

string|null

at line 200
Uri withScheme(string|Stringable $scheme)

Specify the scheme of the URI.

Parameters

string|Stringable $scheme

Return Value

Uri

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

Specify the user and password for the URI.

Parameters

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

Return Value

Uri

at line 216
Uri withHost(string|Stringable $host)

Specify the host of the URI.

Parameters

string|Stringable $host

Return Value

Uri

at line 224
Uri withPort(int|null $port)

Specify the port of the URI.

Parameters

int|null $port

Return Value

Uri

at line 232
Uri withPath(string|Stringable $path)

Specify the path of the URI.

Parameters

string|Stringable $path

Return Value

Uri

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

Merge new query parameters into the URI.

Parameters

array $query
bool $merge

Return Value

Uri

at line 270
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

at line 286
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

at line 303
Uri withoutQuery(array|string $keys)

Remove the given query parameters from the URI.

Parameters

array|string $keys

Return Value

Uri

at line 311
Uri replaceQuery(array $query)

Specify new query parameters for the URI.

Parameters

array $query

Return Value

Uri

at line 319
Uri withFragment(string $fragment)

Specify the fragment of the URI.

Parameters

string $fragment

Return Value

Uri

at line 327
Uri withoutFragment()

Remove the fragment from the URI.

Return Value

Uri

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

Create a redirect HTTP response for the given URI.

Parameters

int $status
array $headers

Return Value

RedirectResponse

at line 343
Stringable toStringable()

Get the URI as a Stringable instance.

Return Value

Stringable

at line 351
Response toResponse(Request $request)

Create an HTTP response that represents the URI object.

Parameters

Request $request

Return Value

Response

at line 359
string toHtml()

Get the URI as a string of HTML.

Return Value

string

at line 367
string decode()

Get the decoded string representation of the URI.

Return Value

string

at line 379
string value()

Get the string representation of the URI.

Return Value

string

at line 387
string toString()

Get the string representation of the URI.

Return Value

string

at line 395
bool isEmpty()

Determine if the URI is currently an empty string.

Return Value

bool

at line 403
bool isNotEmpty()

Determine if the URI is not an empty string.

Return Value

bool

at line 424
static void setUrlGeneratorResolver(Closure $urlGeneratorResolver)

Set the URL generator resolver.

Boot-only. The resolver persists in a static property for the worker lifetime and is used by every subsequent URI route/action helper.

Parameters

Closure $urlGeneratorResolver

Return Value

void

at line 432
UriInterface getUri()

Get the underlying URI instance.

Return Value

UriInterface

at line 440
string jsonSerialize()

Convert the object into a value that is JSON serializable.

Return Value

string

at line 448
string __toString()

Get the string representation of the URI.

Return Value

string

at line 456
static void flushState()

Flush all static state.

Return Value

void