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 array $attributes

The attribute data passed when building the PendingRequest.

from  Request
protected array $context from  HasContext
protected bool $dataChanged

Determine if the request data has changed.

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 JSON decoded 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
withData(array $data)

Add the request data.

array
query()

No description

from  Request
withQuery(array $query = [])

No description

from  Request
withoutQuery(array $keys = [])

No description

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(string|array $key, mixed $value = null)

Set the API request/response context.

mixed
context(string|null $key = null)

Get the API request/response context.

withMethod(string $method)

Set the request method.

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

Set the request URL.

withHeader(string $key, 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, 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.

withoutData(array $data)

Remove the request data.

void
applyChangedData()

No description

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 32
__construct(RequestInterface $request)

Create a new request instance.

Parameters

RequestInterface $request

in Request at line 39
string method()

Get the request method.

Return Value

string

in Request at line 47
string url()

Get the URL of the request.

Return Value

string

in Request at line 55
Uri uri()

Get the request URI as a URI instance.

Return Value

Uri

in Request at line 63
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 83
bool hasHeaders(array|string $headers)

Determine if the request has the given headers.

Parameters

array|string $headers

Return Value

bool

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

Get the values for the header with the given name.

Parameters

string $key

Return Value

array

in Request at line 109
array headers()

Get the request headers.

Return Value

array

in Request at line 117
string body()

Get the body of the request.

Return Value

string

in Request at line 125
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 141
array data()

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

Return Value

array

in Request at line 156
protected array parameters()

Get the request's form parameters.

Return Value

array

in Request at line 170
protected array json()

Get the JSON decoded body of the request.

Return Value

array

in Request at line 182
bool isForm()

Determine if the request is simple form data.

Return Value

bool

in Request at line 190
bool isJson()

Determine if the request is JSON.

Return Value

bool

in Request at line 199
bool isMultipart()

Determine if the request is multipart.

Return Value

bool

at line 193
Request withData(array $data)

Add the request data.

Parameters

array $data

Return Value

Request

in Request at line 215
array query()

No description

Return Value

array

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

No description

Parameters

array $query

Return Value

Request

in Request at line 231
Request withoutQuery(array $keys = [])

No description

Parameters

array $keys

Return Value

Request

in Request at line 245
array attributes()

Get the attribute data from the request.

Return Value

array

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

Set the request's attribute data.

Parameters

array $attributes

Return Value

Request

at line 217
RequestInterface toPsrRequest()

Get the underlying PSR compliant request instance.

Return Value

RequestInterface

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

Determine if the given offset exists.

Parameters

string $offset

Return Value

bool

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

Get the value for a given offset.

Parameters

string $offset

Return Value

mixed

in Request at line 295
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 307
void offsetUnset(string $offset)

Unset the value at the given offset.

Parameters

string $offset

Return Value

void

Exceptions

LogicException

in Request at line 315
static void flushState()

Flush all static state.

Return Value

void

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

Set the API request/response context.

Parameters

string|array $key
mixed $value

Return Value

HasContext

in HasContext at line 30
mixed context(string|null $key = null)

Get the API request/response context.

Parameters

string|null $key

Return Value

mixed

at line 24
ApiRequest withMethod(string $method)

Set the request method.

Parameters

string $method

Return Value

ApiRequest

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

Set the request URL.

Parameters

callable|string $url
bool $preserveHost

Return Value

ApiRequest

at line 48
ApiRequest withHeader(string $key, string $value)

Add the request header.

Parameters

string $key
string $value

Return Value

ApiRequest

at line 56
ApiRequest withHeaders(array $headers)

Add the request headers.

Parameters

array $headers

Return Value

ApiRequest

at line 68
ApiRequest contentType(string $contentType)

Specify the request's content type.

Parameters

string $contentType

Return Value

ApiRequest

at line 78
ApiRequest asForm()

Indicate the request contains form parameters.

Return Value

ApiRequest

at line 94
ApiRequest asJson()

Indicate the request contains JSON.

Return Value

ApiRequest

at line 110
ApiRequest acceptJson()

Indicate that JSON should be returned by the server.

Return Value

ApiRequest

at line 118
ApiRequest accept(string $contentType)

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

Parameters

string $contentType

Return Value

ApiRequest

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

Specify an authorization token for the request.

Parameters

string $token
string $type

Return Value

ApiRequest

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

Specify the user agent for the request.

Parameters

bool|string $userAgent

Return Value

ApiRequest

at line 142
ApiRequest withAddedHeader(string $key, string $value)

Add a request header.

Parameters

string $key
string $value

Return Value

ApiRequest

at line 150
ApiRequest withAddedHeaders(array $headers)

Add request headers.

Parameters

array $headers

Return Value

ApiRequest

at line 162
ApiRequest withoutHeader(string $header)

Remove a request header.

Parameters

string $header

Return Value

ApiRequest

at line 170
ApiRequest withoutHeaders(array $headers)

Remove request headers.

Parameters

array $headers

Return Value

ApiRequest

at line 182
ApiRequest withBody(string $body)

Set the request body.

Parameters

string $body

Return Value

ApiRequest

at line 204
ApiRequest withoutData(array $data)

Remove the request data.

Parameters

array $data

Return Value

ApiRequest

at line 226
protected void applyChangedData()

No description

Return Value

void