class ApiRequest extends Request

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected array $data

The decoded payload for the request.

from  Request
protected bool $hasDecodedData

Determine whether the request data has been decoded.

from  Request
protected array $attributes

The attribute data passed when building the PendingRequest.

from  Request
protected array<string, mixed> $context from  HasContext

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.

from  Request
string
method()

Get the request method.

from  Request
string
url()

Get the URL of the request.

from  Request
Uri
uri()

Get the request URI as a URI instance.

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

Determine if the request has a given header.

from  Request
bool
hasHeaders(array|string $headers)

Determine if the request has the given headers.

from  Request
array
header(string $key)

Get the values for the header with the given name.

from  Request
array
headers()

Get the request headers.

from  Request
string
body()

Get the body of the request.

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

Determine if the request contains the given file.

from  Request
array
data()

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

from  Request
array
parameters()

Get the request's form parameters.

from  Request
array
json()

Get the decoded JSON body of the request.

from  Request
bool
isForm()

Determine if the request is simple form data.

from  Request
bool
isJson()

Determine if the request is JSON.

from  Request
bool
isMultipart()

Determine if the request is multipart.

from  Request
string
mediaType()

Get the normalized request media type.

from  Request
withData(array $data)

Replace the request data.

array
query()

Get the request query parameters.

from  Request
withQuery(array $query = [])

Add query parameters to the request.

from  Request
withoutQuery(array|string $keys = [])

Remove query parameters from the request.

from  Request
array
attributes()

Get the attribute data from the request.

from  Request
setRequestAttributes(array $attributes)

Set the request's attribute data.

from  Request
RequestInterface
toPsrRequest()

Get the underlying PSR compliant request instance.

bool
offsetExists(string $offset)

Determine if the given offset exists.

from  Request
mixed
offsetGet(string $offset)

Get the value for a given offset.

from  Request
void
offsetSet(string $offset, mixed $value)

Set the value at the given offset.

from  Request
void
offsetUnset(string $offset)

Unset the value at the given offset.

from  Request
static void
flushState()

Flush all static state.

from  Request
withContext(array|string $key, mixed $value = null)

Set the API request/response context.

mixed
context(string|null $key = null, mixed $default = null)

Get the API request/response context.

static ApiRequest
createFrom(Request $request)

Create an API request from an HTTP client request.

withMethod(string $method)

Set the request method.

withUrl(callable|string $url, bool $preserveHost = false)

Set the request URL.

withHeader(string $key, array|string $value)

Add the request header.

withHeaders(array $headers)

Add the request headers.

contentType(string $contentType)

Specify the request's content type.

asForm()

Indicate the request contains form parameters.

asJson()

Indicate the request contains JSON.

acceptJson()

Indicate that JSON should be returned by the server.

accept(string $contentType)

Indicate the type of content that should be returned by the server.

withToken(string $token, string $type = 'Bearer')

Specify an authorization token for the request.

withUserAgent(bool|string $userAgent)

Specify the user agent for the request.

withAddedHeader(string $key, array|string $value)

Add a request header.

withAddedHeaders(array $headers)

Add request headers.

withoutHeader(string $header)

Remove a request header.

withoutHeaders(array $headers)

Remove request headers.

withBody(string $body)

Set the request body.

mergeData(array $data)

Merge the request data.

withoutData(array|string $keys)

Remove keys from the request data.

void
applyChangedData()

Apply changed structured data to the request body.

void
ensureStructuredMutationAllowed()

Ensure structured data may be changed for the request.

void
ensureStructuredBody()

Ensure the request body has a supported structured representation.

void
replaceBody(string $body)

Replace the request body and update its framing headers.

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

in Request at line 39
__construct(RequestInterface $request)

Create a new request instance.

Parameters

RequestInterface $request

in Request at line 46
string method()

Get the request method.

Return Value

string

in Request at line 54
string url()

Get the URL of the request.

Return Value

string

in Request at line 62
Uri uri()

Get the request URI as a URI instance.

Return Value

Uri

in Request 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

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

Determine if the request has the given headers.

Parameters

array|string $headers

Return Value

bool

in Request at line 100
array header(string $key)

Get the values for the header with the given name.

Parameters

string $key

Return Value

array

in Request at line 108
array headers()

Get the request headers.

Return Value

array

in Request at line 116
string body()

Get the body of the request.

Return Value

string

in Request 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

in Request at line 143
array data()

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

Return Value

array

Exceptions

InvalidArgumentException
JsonException

in Request at line 158
protected array parameters()

Get the request's form parameters.

Return Value

array

in Request at line 176
protected array json()

Get the decoded JSON body of the request.

Return Value

array

Exceptions

InvalidArgumentException
JsonException

in Request at line 203
bool isForm()

Determine if the request is simple form data.

Return Value

bool

in Request at line 211
bool isJson()

Determine if the request is JSON.

Return Value

bool

in Request at line 219
bool isMultipart()

Determine if the request is multipart.

Return Value

bool

in Request at line 227
protected string mediaType()

Get the normalized request media type.

Return Value

string

at line 220
Request withData(array $data)

Replace the request data.

Parameters

array $data

Return Value

Request

Exceptions

InvalidArgumentException
JsonException

in Request at line 251
array query()

Get the request query parameters.

Return Value

array

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

Add query parameters to the request.

Parameters

array $query

Return Value

Request

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

Remove query parameters from the request.

Parameters

array|string $keys

Return Value

Request

in Request at line 287
array attributes()

Get the attribute data from the request.

Return Value

array

in Request at line 295
Request setRequestAttributes(array $attributes)

Set the request's attribute data.

Parameters

array $attributes

Return Value

Request

at line 268
RequestInterface toPsrRequest()

Get the underlying PSR compliant request instance.

Return Value

RequestInterface

in Request at line 315
bool offsetExists(string $offset)

Determine if the given offset exists.

Parameters

string $offset

Return Value

bool

in Request at line 325
mixed offsetGet(string $offset)

Get the value for a given offset.

Parameters

string $offset

Return Value

mixed

in Request 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

in Request at line 349
void offsetUnset(string $offset)

Unset the value at the given offset.

Parameters

string $offset

Return Value

void

Exceptions

LogicException

in Request at line 357
static void flushState()

Flush all static state.

Return Value

void

in HasContext at line 19
HasContext withContext(array|string $key, mixed $value = null)

Set the API request/response context.

Parameters

array|string $key
mixed $value

Return Value

HasContext

in HasContext at line 35
mixed context(string|null $key = null, mixed $default = null)

Get the API request/response context.

Parameters

string|null $key
mixed $default

Return Value

mixed

at line 24
static ApiRequest createFrom(Request $request)

Create an API request from an HTTP client request.

Parameters

Request $request

Return Value

ApiRequest

at line 37
ApiRequest withMethod(string $method)

Set the request method.

Parameters

string $method

Return Value

ApiRequest

at line 47
ApiRequest withUrl(callable|string $url, bool $preserveHost = false)

Set the request URL.

Parameters

callable|string $url
bool $preserveHost

Return Value

ApiRequest

at line 61
ApiRequest withHeader(string $key, array|string $value)

Add the request header.

Parameters

string $key
array|string $value

Return Value

ApiRequest

at line 69
ApiRequest withHeaders(array $headers)

Add the request headers.

Parameters

array $headers

Return Value

ApiRequest

at line 81
ApiRequest contentType(string $contentType)

Specify the request's content type.

Parameters

string $contentType

Return Value

ApiRequest

at line 94
ApiRequest asForm()

Indicate the request contains form parameters.

Return Value

ApiRequest

Exceptions

InvalidArgumentException
JsonException

at line 115
ApiRequest asJson()

Indicate the request contains JSON.

Return Value

ApiRequest

Exceptions

InvalidArgumentException
JsonException

at line 133
ApiRequest acceptJson()

Indicate that JSON should be returned by the server.

Return Value

ApiRequest

at line 141
ApiRequest accept(string $contentType)

Indicate the type of content that should be returned by the server.

Parameters

string $contentType

Return Value

ApiRequest

at line 149
ApiRequest withToken(string $token, string $type = 'Bearer')

Specify an authorization token for the request.

Parameters

string $token
string $type

Return Value

ApiRequest

at line 157
ApiRequest withUserAgent(bool|string $userAgent)

Specify the user agent for the request.

Parameters

bool|string $userAgent

Return Value

ApiRequest

at line 165
ApiRequest withAddedHeader(string $key, array|string $value)

Add a request header.

Parameters

string $key
array|string $value

Return Value

ApiRequest

at line 173
ApiRequest withAddedHeaders(array $headers)

Add request headers.

Parameters

array $headers

Return Value

ApiRequest

at line 185
ApiRequest withoutHeader(string $header)

Remove a request header.

Parameters

string $header

Return Value

ApiRequest

at line 193
ApiRequest withoutHeaders(array $headers)

Remove request headers.

Parameters

array $headers

Return Value

ApiRequest

at line 205
ApiRequest withBody(string $body)

Set the request body.

Parameters

string $body

Return Value

ApiRequest

at line 237
ApiRequest mergeData(array $data)

Merge the request data.

Parameters

array $data

Return Value

ApiRequest

Exceptions

InvalidArgumentException
JsonException

at line 254
ApiRequest withoutData(array|string $keys)

Remove keys from the request data.

Parameters

array|string $keys

Return Value

ApiRequest

Exceptions

InvalidArgumentException
JsonException

at line 278
protected void applyChangedData()

Apply changed structured data to the request body.

Return Value

void

Exceptions

JsonException

at line 298
protected void ensureStructuredMutationAllowed()

Ensure structured data may be changed for the request.

Return Value

void

Exceptions

InvalidArgumentException

at line 314
protected void ensureStructuredBody()

Ensure the request body has a supported structured representation.

Return Value

void

Exceptions

InvalidArgumentException

at line 328
protected void replaceBody(string $body)

Replace the request body and update its framing headers.

Parameters

string $body

Return Value

void