class PendingRequest

Traits

Properties

protected Authenticator|null $authenticator

The authenticator used in requests.

from  AuthenticatesRequests
protected BodyRepository|null $bodyRepository

The request body repository.

from  HasBody
protected list<array<string, mixed>> $cookies

The request cookies and their attributes.

from  HasCookies
protected IntegerRepository|null $delayRepository

The request delay.

from  HasDelay
protected ArrayRepository|null $headerRepository

The request headers.

from  HasHeaders
protected MiddlewarePipeline|null $middlewarePipeline

The request middleware pipeline.

from  HasMiddleware
protected ArrayRepository|null $optionRepository

The request options.

from  HasOptions
protected ArrayRepository|null $queryRepository

The request query parameters.

from  HasQuery
protected string|null $queryString

The already-encoded query string override.

from  HasQuery
protected RetryPolicy|null $retryPolicy

The request retry policy.

from  HasRetryPolicy
static protected array $macros

The registered string macros.

from  Macroable
protected UriInterface|null $uri

The finalized request URI.

protected StreamInterface|null $preparedBody

The prepared request body.

protected bool $bodyPrepared

Whether the operation body has been prepared.

protected int|null $attemptBodyOffset

The body offset at the start of the transport attempt.

protected RequestInterface|null $psrRequest

The final application-owned PSR request.

protected PendingRequest): void> $psrRequestObservers

The final PSR request observers.

protected null|array{0: string, 1: string, 2?: string} $transportAuthentication

The dedicated transport authentication option.

protected null|array{0: string, 1: string}|string $certificate

The dedicated client certificate option.

protected FakeResponse|null $fakeResponse

The response supplied by request middleware or a mock client.

Methods

defaultAuth()

Resolve the default authenticator.

authenticator()

Get the authenticator.

authenticate(Authenticator $authenticator)

Authenticate the pending request immediately.

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

Authenticate the request with a token.

withBasicAuth(string $username, string $password)

Authenticate the request with basic authentication.

withDigestAuth(string $username, string $password)

Authenticate the request with digest authentication.

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.

withBody(mixed $content, string|null $contentType = 'application/json')

Set the raw request body.

from  HasBody
asJson(array $data = [])

Use a JSON request body.

from  HasBody
asForm(array $data = [])

Use a URL-encoded form request body.

from  HasBody
asMultipart()

Use a multipart request body.

from  HasBody
attach(string $name, mixed $contents = '', string|null $filename = null, array $headers = [])

Attach a multipart value to the request.

from  HasBody
withData(array $data)

Merge structured values into the request body.

from  HasBody
mixed
body()

Get the resolved request body value.

from  HasBody
bool
hasBody()

Determine if the request has a body repository.

from  HasBody
copyBodyRepository()

Copy the body repository for a pending request.

from  HasBody
defaultBodyRepository()

Resolve the default body repository.

from  HasBody
bodyRepository()

Get the request body repository.

from  HasBody
debugRequest(callable|null $onRequest = null, bool $die = false)

Debug the final application-owned request.

debugResponse(callable|null $onResponse = null, bool $die = false)

Debug the response before ordinary response middleware.

debug(bool $die = false)

Debug both the request and response.

withCookie(SetCookie $cookie)

Specify a cookie and its attributes for the request.

withCookies(array $cookies, string $domain)

Specify cookies that should be included with the request.

array
cookies()

Get the request cookies and their attributes.

delay(int $milliseconds)

Delay the request by the given milliseconds.

from  HasDelay
int|null
delayMilliseconds()

Get the request delay in milliseconds.

from  HasDelay
int|null
defaultDelay()

Resolve the default request delay.

from  HasDelay
delayRepository()

Get the request delay repository.

from  HasDelay
array
headers()

Get the request headers.

bool
hasHeader(string $name)

Determine if the request contains the given header.

withHeaders(array $headers)

Add headers to the request.

withHeader(string $name, mixed $value)

Add a header to the request.

replaceHeaders(array $headers)

Replace matching headers on the request.

contentType(string $contentType)

Specify the request content type.

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.

withUserAgent(bool|string $userAgent)

Specify the request user agent.

array
defaultHeaders()

Resolve the default request headers.

headerRepository()

Get the request header repository.

middleware()

Get the request middleware pipeline.

array
options()

Get the request options.

withOptions(array $options)

Add options to the request.

maxRedirects(int $max)

Specify the maximum number of redirects to allow.

withoutRedirecting()

Indicate that redirects should not be followed.

withoutVerifying()

Indicate that TLS certificates should not be verified.

sink(resource|StreamInterface|string $to)

Specify where the response body should be stored.

timeout(float|int $seconds)

Specify the request timeout in seconds.

connectTimeout(float|int $seconds)

Specify the connection timeout in seconds.

withTelescopeTags(array $tags)

Add Telescope tags to the request.

withoutTelescope()

Disable Telescope recording for the request.

array
defaultOptions()

Resolve the default request options.

optionRepository()

Get the request option repository.

string|null
queryString()

Get the raw query string override, without a leading question mark.

from  HasQuery
withQueryString(string $query)

Replace the raw query string and invalidate the finalized URI.

array
queryParameters()

Get the request query parameters.

from  HasQuery
withQueryParameters(array $parameters)

Add query parameters to the request.

array
defaultQuery()

Resolve the default request query parameters.

from  HasQuery
string|null
defaultQueryString()

Resolve the default raw query string override.

from  HasQuery
queryRepository()

Get the request query repository.

from  HasQuery
retry(array|int $times, Closure|int $sleepMilliseconds = 0, callable|null $when = null, bool $throw = true)

Specify the number of times the request should be attempted.

retryPolicy()

Get the request retry policy.

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(Connector $connector, Request $request, Factory $cache, RateLimiter $rateLimiter)

Create a side-effect-free pending request.

connector()

Get the connector.

request()

Get the request.

Method
method()

Get the HTTP method.

UriInterface
uri()

Get the final request URI.

finalizeUri()

Finalize the request URI after ordinary request middleware.

applyAuthentication()

Apply the configured authenticator.

bootPlugins()

Boot the connector and request plugins.

mergeMiddleware(MiddlewarePipeline $middleware)

Merge worker-global middleware into this operation.

executeRequestPipeline()

Execute the request middleware pipeline.

executeResponsePipeline(Response $response)

Execute the response middleware pipeline.

void
executeFatalPipeline(FatalRequestException $exception)

Execute the fatal exception middleware pipeline.

prepareBody()

Prepare the request body after ordinary request middleware.

StreamInterface|null
preparedBody()

Get the prepared request body.

setTransportAuthentication(array $authentication)

Set the dedicated transport authentication option.

array|null
transportAuthentication()

Get the dedicated transport authentication option.

setCertificate(string $path, string|null $password = null)

Set the client certificate option.

array|string|null
certificate()

Get the client certificate option.

observePsrRequest(callable $observer)

Observe the final application-owned PSR request.

RequestInterface
handlePsrRequest(RequestInterface $request)

Apply the connector and request PSR hooks.

void
notifyPsrRequestObservers(RequestInterface $request)

Notify the final PSR request observers.

RequestInterface
createPsrRequest()

Create the logical PSR request for a short-circuit response.

setPsrRequest(RequestInterface $request)

Set the final application-owned PSR request.

RequestInterface
toPsrRequest()

Get the captured PSR request or create a logical snapshot.

bool
restoreAttemptBody()

Restore the attempt body before another attempt.

setFakeResponse(FakeResponse|null $fakeResponse)

Set the fake response.

fakeResponse()

Get the fake response.

validateCachingConfiguration()

Validate the request's caching configuration.

bool
isCacheable()

Determine if this operation is cacheable.

bool
shouldInvalidateCache()

Determine if the matching cache entry should be invalidated.

cacheFor()

Get the cache duration.

UnitEnum|string|null
cacheStore()

Get the selected cache store.

string|null
resolveCacheKey()

Resolve the custom cache key.

cache()

Get the cache factory.

rateLimiter()

Get the rate limiter manager.

Cacheable|null
cacheableResource()

Resolve the request or connector that owns cache duration and storage.

createResponse(Response $response, RequestInterface $request)

Create the response selected by this operation.

string|null
resolveResponseClass(Response $response)

Resolve the custom response class.

int|null
streamOffset(StreamInterface|null $stream)

Get the current offset of a seekable stream.

string|null
multipartContentType()

Resolve the multipart content type when the caller did not provide one.

static void
flushState()

Flush all static state.

Details

protected Authenticator|null defaultAuth()

Resolve the default authenticator.

Return Value

Authenticator|null

Authenticator|null authenticator()

Get the authenticator.

Return Value

Authenticator|null

at line 242
PendingRequest authenticate(Authenticator $authenticator)

Authenticate the pending request immediately.

Parameters

Authenticator $authenticator

Return Value

PendingRequest

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

Authenticate the request with a token.

Parameters

string $token
string $type

Return Value

AuthenticatesRequests

AuthenticatesRequests withBasicAuth(string $username, string $password)

Authenticate the request with basic authentication.

Parameters

string $username
string $password

Return Value

AuthenticatesRequests

AuthenticatesRequests withDigestAuth(string $username, string $password)

Authenticate the request with digest authentication.

Parameters

string $username
string $password

Return Value

AuthenticatesRequests

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 HasBody at line 31
HasBody withBody(mixed $content, string|null $contentType = 'application/json')

Set the raw request body.

Parameters

mixed $content
string|null $contentType

Return Value

HasBody

in HasBody at line 50
HasBody asJson(array $data = [])

Use a JSON request body.

Parameters

array $data

Return Value

HasBody

in HasBody at line 63
HasBody asForm(array $data = [])

Use a URL-encoded form request body.

Parameters

array $data

Return Value

HasBody

in HasBody at line 75
HasBody asMultipart()

Use a multipart request body.

Return Value

HasBody

in HasBody at line 89
HasBody attach(string $name, mixed $contents = '', string|null $filename = null, array $headers = [])

Attach a multipart value to the request.

Parameters

string $name
mixed $contents
string|null $filename
array $headers

Return Value

HasBody

in HasBody at line 112
HasBody withData(array $data)

Merge structured values into the request body.

Parameters

array $data

Return Value

HasBody

in HasBody at line 129
mixed body()

Get the resolved request body value.

Return Value

mixed

in HasBody at line 137
bool hasBody()

Determine if the request has a body repository.

Return Value

bool

in HasBody at line 147
final BodyRepository|null copyBodyRepository()

internal  
 

Copy the body repository for a pending request.

Return Value

BodyRepository|null

in HasBody at line 157
protected BodyRepository|null defaultBodyRepository()

Resolve the default body repository.

Return Value

BodyRepository|null

in HasBody at line 165
protected BodyRepository|null bodyRepository()

Get the request body repository.

Return Value

BodyRepository|null

in HasDebugging at line 22
HasDebugging debugRequest(callable|null $onRequest = null, bool $die = false)

Debug the final application-owned request.

Parameters

callable|null $onRequest
bool $die

Return Value

HasDebugging

in HasDebugging at line 50
HasDebugging debugResponse(callable|null $onResponse = null, bool $die = false)

Debug the response before ordinary response middleware.

Parameters

callable|null $onResponse
bool $die

Return Value

HasDebugging

in HasDebugging at line 81
HasDebugging debug(bool $die = false)

Debug both the request and response.

Raw debugging output may contain credentials or other sensitive values.

Parameters

bool $die

Return Value

HasDebugging

in HasCookies at line 25
HasCookies withCookie(SetCookie $cookie)

Specify a cookie and its attributes for the request.

Parameters

SetCookie $cookie

Return Value

HasCookies

in HasCookies at line 46
HasCookies withCookies(array $cookies, string $domain)

Specify cookies that should be included with the request.

Parameters

array $cookies
string $domain

Return Value

HasCookies

in HasCookies at line 60
array cookies()

Get the request cookies and their attributes.

Return Value

array

in HasDelay at line 22
HasDelay delay(int $milliseconds)

Delay the request by the given milliseconds.

Parameters

int $milliseconds

Return Value

HasDelay

in HasDelay at line 36
int|null delayMilliseconds()

Get the request delay in milliseconds.

Return Value

int|null

in HasDelay at line 44
protected int|null defaultDelay()

Resolve the default request delay.

Return Value

int|null

in HasDelay at line 52
protected IntegerRepository delayRepository()

Get the request delay repository.

Return Value

IntegerRepository

in HasHeaders at line 21
array headers()

Get the request headers.

Return Value

array

in HasHeaders at line 29
bool hasHeader(string $name)

Determine if the request contains the given header.

Parameters

string $name

Return Value

bool

in HasHeaders at line 46
HasHeaders withHeaders(array $headers)

Add headers to the request.

Parameters

array $headers

Return Value

HasHeaders

in HasHeaders at line 58
HasHeaders withHeader(string $name, mixed $value)

Add a header to the request.

Parameters

string $name
mixed $value

Return Value

HasHeaders

in HasHeaders at line 69
HasHeaders replaceHeaders(array $headers)

Replace matching headers on the request.

Parameters

array $headers

Return Value

HasHeaders

in HasHeaders at line 97
HasHeaders contentType(string $contentType)

Specify the request content type.

Parameters

string $contentType

Return Value

HasHeaders

in HasHeaders at line 107
HasHeaders acceptJson()

Indicate that JSON should be returned by the server.

Return Value

HasHeaders

in HasHeaders at line 117
HasHeaders accept(string $contentType)

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

Parameters

string $contentType

Return Value

HasHeaders

in HasHeaders at line 127
HasHeaders withUserAgent(bool|string $userAgent)

Specify the request user agent.

Parameters

bool|string $userAgent

Return Value

HasHeaders

in HasHeaders at line 137
protected array defaultHeaders()

Resolve the default request headers.

Return Value

array

in HasHeaders at line 145
protected ArrayRepository headerRepository()

Get the request header repository.

Return Value

ArrayRepository

in HasMiddleware at line 19
MiddlewarePipeline middleware()

Get the request middleware pipeline.

Return Value

MiddlewarePipeline

in HasOptions at line 23
array options()

Get the request options.

Return Value

array

in HasOptions at line 34
HasOptions withOptions(array $options)

Add options to the request.

Parameters

array $options

Return Value

HasOptions

in HasOptions at line 46
HasOptions maxRedirects(int $max)

Specify the maximum number of redirects to allow.

Parameters

int $max

Return Value

HasOptions

in HasOptions at line 64
HasOptions withoutRedirecting()

Indicate that redirects should not be followed.

Return Value

HasOptions

in HasOptions at line 74
HasOptions withoutVerifying()

Indicate that TLS certificates should not be verified.

Return Value

HasOptions

in HasOptions at line 85
HasOptions sink(resource|StreamInterface|string $to)

Specify where the response body should be stored.

Parameters

resource|StreamInterface|string $to

Return Value

HasOptions

in HasOptions at line 95
HasOptions timeout(float|int $seconds)

Specify the request timeout in seconds.

Parameters

float|int $seconds

Return Value

HasOptions

in HasOptions at line 105
HasOptions connectTimeout(float|int $seconds)

Specify the connection timeout in seconds.

Parameters

float|int $seconds

Return Value

HasOptions

in HasOptions at line 116
HasOptions withTelescopeTags(array $tags)

Add Telescope tags to the request.

Parameters

array $tags

Return Value

HasOptions

in HasOptions at line 126
HasOptions withoutTelescope()

Disable Telescope recording for the request.

Return Value

HasOptions

in HasOptions at line 136
protected array defaultOptions()

Resolve the default request options.

Return Value

array

in HasOptions at line 144
protected ArrayRepository optionRepository()

Get the request option repository.

Return Value

ArrayRepository

in HasQuery at line 24
string|null queryString()

Get the raw query string override, without a leading question mark.

Return Value

string|null

at line 230
PendingRequest withQueryString(string $query)

Replace the raw query string and invalidate the finalized URI.

Parameters

string $query

Return Value

PendingRequest

in HasQuery at line 44
array queryParameters()

Get the request query parameters.

Return Value

array

at line 219
PendingRequest withQueryParameters(array $parameters)

Add query parameters to the request.

Parameters

array $parameters

Return Value

PendingRequest

in HasQuery at line 67
protected array defaultQuery()

Resolve the default request query parameters.

Return Value

array

in HasQuery at line 75
protected string|null defaultQueryString()

Resolve the default raw query string override.

Return Value

string|null

in HasQuery at line 83
protected ArrayRepository queryRepository()

Get the request query repository.

Return Value

ArrayRepository

in HasRetryPolicy at line 23
HasRetryPolicy retry(array|int $times, Closure|int $sleepMilliseconds = 0, callable|null $when = null, bool $throw = true)

Specify the number of times the request should be attempted.

Parameters

array|int $times
Closure|int $sleepMilliseconds
callable|null $when
bool $throw

Return Value

HasRetryPolicy

in HasRetryPolicy at line 37
RetryPolicy retryPolicy()

Get the request retry policy.

Return Value

RetryPolicy

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 110
__construct(Connector $connector, Request $request, Factory $cache, RateLimiter $rateLimiter)

Create a side-effect-free pending request.

Parameters

Connector $connector
Request $request
Factory $cache
RateLimiter $rateLimiter

at line 155
Connector connector()

Get the connector.

Return Value

Connector

at line 165
Request request()

Get the request.

Return Value

Request

at line 173
Method method()

Get the HTTP method.

Return Value

Method

at line 181
UriInterface uri()

Get the final request URI.

Return Value

UriInterface

at line 206
PendingRequest finalizeUri()

Finalize the request URI after ordinary request middleware.

Return Value

PendingRequest

at line 253
PendingRequest applyAuthentication()

Apply the configured authenticator.

Return Value

PendingRequest

at line 263
PendingRequest bootPlugins()

Boot the connector and request plugins.

Return Value

PendingRequest

at line 273
PendingRequest mergeMiddleware(MiddlewarePipeline $middleware)

Merge worker-global middleware into this operation.

Parameters

MiddlewarePipeline $middleware

Return Value

PendingRequest

at line 283
PendingRequest executeRequestPipeline()

Execute the request middleware pipeline.

Return Value

PendingRequest

at line 293
Response executeResponsePipeline(Response $response)

Execute the response middleware pipeline.

Parameters

Response $response

Return Value

Response

at line 301
void executeFatalPipeline(FatalRequestException $exception)

Execute the fatal exception middleware pipeline.

Parameters

FatalRequestException $exception

Return Value

void

at line 309
PendingRequest prepareBody()

Prepare the request body after ordinary request middleware.

Return Value

PendingRequest

at line 329
StreamInterface|null preparedBody()

Get the prepared request body.

Return Value

StreamInterface|null

at line 340
PendingRequest setTransportAuthentication(array $authentication)

Set the dedicated transport authentication option.

Parameters

array $authentication

Return Value

PendingRequest

at line 352
array|null transportAuthentication()

Get the dedicated transport authentication option.

Return Value

array|null

at line 362
PendingRequest setCertificate(string $path, string|null $password = null)

Set the client certificate option.

Parameters

string $path
string|null $password

Return Value

PendingRequest

at line 374
array|string|null certificate()

Get the client certificate option.

Return Value

array|string|null

at line 385
PendingRequest observePsrRequest(callable $observer)

Observe the final application-owned PSR request.

Parameters

callable $observer

Return Value

PendingRequest

at line 395
RequestInterface handlePsrRequest(RequestInterface $request)

Apply the connector and request PSR hooks.

Parameters

RequestInterface $request

Return Value

RequestInterface

at line 405
void notifyPsrRequestObservers(RequestInterface $request)

Notify the final PSR request observers.

Parameters

RequestInterface $request

Return Value

void

at line 417
RequestInterface createPsrRequest()

internal  
 

Create the logical PSR request for a short-circuit response.

Return Value

RequestInterface

at line 443
PendingRequest setPsrRequest(RequestInterface $request)

Set the final application-owned PSR request.

Parameters

RequestInterface $request

Return Value

PendingRequest

at line 458
RequestInterface toPsrRequest()

Get the captured PSR request or create a logical snapshot.

Before authoritative capture, the snapshot does not run PSR hooks or observers. It materializes the body from its repository instead of reusing a prepared stream, though caller-owned streams may be shared.

Return Value

RequestInterface

at line 482
bool restoreAttemptBody()

Restore the attempt body before another attempt.

Return Value

bool

at line 504
PendingRequest setFakeResponse(FakeResponse|null $fakeResponse)

Set the fake response.

Parameters

FakeResponse|null $fakeResponse

Return Value

PendingRequest

at line 514
FakeResponse|null fakeResponse()

Get the fake response.

Return Value

FakeResponse|null

at line 522
PendingRequest validateCachingConfiguration()

Validate the request's caching configuration.

Return Value

PendingRequest

at line 537
bool isCacheable()

Determine if this operation is cacheable.

Return Value

bool

at line 550
bool shouldInvalidateCache()

Determine if the matching cache entry should be invalidated.

Return Value

bool

at line 558
DateInterval|DateTimeInterface|int cacheFor()

Get the cache duration.

Return Value

DateInterval|DateTimeInterface|int

at line 567
UnitEnum|string|null cacheStore()

Get the selected cache store.

Return Value

UnitEnum|string|null

at line 581
string|null resolveCacheKey()

Resolve the custom cache key.

Return Value

string|null

at line 590
Factory cache()

Get the cache factory.

Return Value

Factory

at line 598
RateLimiter rateLimiter()

Get the rate limiter manager.

Return Value

RateLimiter

at line 606
protected Cacheable|null cacheableResource()

Resolve the request or connector that owns cache duration and storage.

Return Value

Cacheable|null

at line 620
Response createResponse(Response $response, RequestInterface $request)

Create the response selected by this operation.

Parameters

Response $response
RequestInterface $request

Return Value

Response

at line 635
string|null resolveResponseClass(Response $response)

Resolve the custom response class.

Parameters

Response $response

Return Value

string|null

at line 650
protected int|null streamOffset(StreamInterface|null $stream)

Get the current offset of a seekable stream.

Parameters

StreamInterface|null $stream

Return Value

int|null

at line 658
protected string|null multipartContentType()

Resolve the multipart content type when the caller did not provide one.

Return Value

string|null

at line 670
static void flushState()

Flush all static state.

Return Value

void