class Request implements ArrayAccess

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected array $data

The decoded payload for the request.

protected bool $hasDecodedData

Determine whether the request data has been decoded.

protected array $attributes

The attribute data passed when building the PendingRequest.

Methods

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.

__construct(RequestInterface $request)

Create a new request instance.

string
method()

Get the request method.

string
url()

Get the URL of the request.

Uri
uri()

Get the request URI as a URI instance.

bool
hasHeader(string $key, mixed $value = null)

Determine if the request has a given header.

bool
hasHeaders(array|string $headers)

Determine if the request has the given headers.

array
header(string $key)

Get the values for the header with the given name.

array
headers()

Get the request headers.

string
body()

Get the body of the request.

bool
hasFile(string $name, string|null $value = null, string|null $filename = null)

Determine if the request contains the given file.

array
data()

Get the request's data (form parameters or JSON).

array
parameters()

Get the request's form parameters.

array
json()

Get the decoded JSON body of the request.

bool
isForm()

Determine if the request is simple form data.

bool
isJson()

Determine if the request is JSON.

bool
isMultipart()

Determine if the request is multipart.

string
mediaType()

Get the normalized request media type.

withData(array $data)

Set the logical data on the request.

array
query()

Get the request query parameters.

withQuery(array $query = [])

Add query parameters to the request.

withoutQuery(array|string $keys = [])

Remove query parameters from the request.

array
attributes()

Get the attribute data from the request.

setRequestAttributes(array $attributes)

Set the request's attribute data.

RequestInterface
toPsrRequest()

Get the underlying PSR compliant request instance.

bool
offsetExists(string $offset)

Determine if the given offset exists.

mixed
offsetGet(string $offset)

Get the value for a given offset.

void
offsetSet(string $offset, mixed $value)

Set the value at the given offset.

void
offsetUnset(string $offset)

Unset the value at the given offset.

static void
flushState()

Flush all static state.

Details

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

at line 39
__construct(RequestInterface $request)

Create a new request instance.

Parameters

RequestInterface $request

at line 46
string method()

Get the request method.

Return Value

string

at line 54
string url()

Get the URL of the request.

Return Value

string

at line 62
Uri uri()

Get the request URI as a URI instance.

Return Value

Uri

at line 70
bool hasHeader(string $key, mixed $value = null)

Determine if the request has a given header.

Parameters

string $key
mixed $value

Return Value

bool

at line 88
bool hasHeaders(array|string $headers)

Determine if the request has the given headers.

Parameters

array|string $headers

Return Value

bool

at line 100
array header(string $key)

Get the values for the header with the given name.

Parameters

string $key

Return Value

array

at line 108
array headers()

Get the request headers.

Return Value

array

at line 116
string body()

Get the body of the request.

Return Value

string

at line 124
bool hasFile(string $name, string|null $value = null, string|null $filename = null)

Determine if the request contains the given file.

Parameters

string $name
string|null $value
string|null $filename

Return Value

bool

at line 143
array data()

Get the request's data (form parameters or JSON).

Return Value

array

Exceptions

InvalidArgumentException
JsonException

at line 158
protected array parameters()

Get the request's form parameters.

Return Value

array

at line 176
protected array json()

Get the decoded JSON body of the request.

Return Value

array

Exceptions

InvalidArgumentException
JsonException

at line 203
bool isForm()

Determine if the request is simple form data.

Return Value

bool

at line 211
bool isJson()

Determine if the request is JSON.

Return Value

bool

at line 219
bool isMultipart()

Determine if the request is multipart.

Return Value

bool

at line 227
protected string mediaType()

Get the normalized request media type.

Return Value

string

at line 241
Request withData(array $data)

Set the logical data on the request.

This does not mark the body as decoded, so a final JSON or form body may replace it.

Parameters

array $data

Return Value

Request

at line 251
array query()

Get the request query parameters.

Return Value

array

at line 261
Request withQuery(array $query = [])

Add query parameters to the request.

Parameters

array $query

Return Value

Request

at line 273
Request withoutQuery(array|string $keys = [])

Remove query parameters from the request.

Parameters

array|string $keys

Return Value

Request

at line 287
array attributes()

Get the attribute data from the request.

Return Value

array

at line 295
Request setRequestAttributes(array $attributes)

Set the request's attribute data.

Parameters

array $attributes

Return Value

Request

at line 305
RequestInterface toPsrRequest()

Get the underlying PSR compliant request instance.

Return Value

RequestInterface

at line 315
bool offsetExists(string $offset)

Determine if the given offset exists.

Parameters

string $offset

Return Value

bool

at line 325
mixed offsetGet(string $offset)

Get the value for a given offset.

Parameters

string $offset

Return Value

mixed

at line 337
void offsetSet(string $offset, mixed $value)

Set the value at the given offset.

Parameters

string $offset
mixed $value

Return Value

void

Exceptions

LogicException

at line 349
void offsetUnset(string $offset)

Unset the value at the given offset.

Parameters

string $offset

Return Value

void

Exceptions

LogicException

at line 357
static void flushState()

Flush all static state.

Return Value

void