PendingRequest
class PendingRequest
Traits
Every request and pending request uses this trait, so body traits need no upstream HasBody contract or
ChecksForHasBody check.
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 int|null | $delay | The request delay in milliseconds. |
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 |
| protected array<array-key, mixed> | $urlParameters | The parameters substituted into URL templates. |
from HasUrlParameters |
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected Method | $method | The HTTP method used by the operation. |
|
| protected string|null | $url | The absolute URL override. |
|
| 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 array<string, true> | $authenticationHeaderNames | The header names restricted to the request's origin. |
|
| protected bool | $authenticating | Whether header writes belong to an authenticator. |
|
| 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. |
|
| protected bool | $bootingPlugins | Whether the connector and request plugins are booting. |
Methods
Authenticate the request with a token.
Authenticate the request with basic authentication.
Authenticate the request with digest authentication.
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Set the raw request body.
Use a multipart request body, keeping any existing multipart values.
Attach a multipart value to the request.
Copy the body repository for a pending request.
Debug the final application-owned request.
Debug the response before ordinary response middleware.
Specify a cookie and its attributes for the request.
Specify cookies that should be included with the request.
Add headers to the request.
Replace matching headers on the request.
Indicate the type of content that should be returned by the server.
Remove the given options from the request.
Indicate that TLS certificates should not be verified.
Specify where the response body should be stored.
Specify the connection timeout in seconds.
Get the raw query string override, without a leading question mark.
Replace the raw query string and invalidate the finalized URI.
Add query parameters to the request.
Remove query parameters and invalidate the finalized URI.
Specify the number of times the request should be attempted.
Specify the URL parameters and invalidate the finalized URI.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Get the HTTP method.
Change the HTTP method used by the operation.
Get the absolute URL override.
Replace the connector base URL and request endpoint for this operation.
Get the final request URI.
Finalize the request URI after ordinary request middleware.
Apply the selected authenticator.
Apply an authenticator while recording its header writes.
Boot the connector and request plugins.
Merge global or request middleware into this operation's own pipeline.
Execute the request middleware pipeline.
Execute the fatal exception middleware pipeline.
Prepare the request body after ordinary request middleware.
Get the prepared request body.
Record headers written during authentication, including unchanged values.
Get the authentication header names.
Set the dedicated transport authentication option.
Get the dedicated transport authentication option.
Set the client certificate option.
Get the client certificate option.
Observe the final application-owned PSR request.
Apply the connector and request PSR hooks.
Notify the final PSR request observers.
Create the logical PSR request for a short-circuit response.
Set the final application-owned PSR request.
Get the captured PSR request or create a logical snapshot.
Restore the attempt body before another attempt.
Get the fake response.
Validate the request's caching configuration.
Determine if this operation is cacheable.
Determine if the matching cache entry should be invalidated.
Get the cache duration.
Get the selected cache store.
Resolve the custom cache key.
Resolve the request or connector that owns cache duration and storage.
Create the response selected by this operation.
Get the current offset of a seekable stream.
Resolve the multipart content type unless the caller provided one with a boundary.
Flush all static state.
Details
in
AuthenticatesRequests at line 23
protected Authenticator|null
defaultAuth()
Resolve the default authenticator.
in
AuthenticatesRequests at line 31
Authenticator|null
authenticator()
Get the authenticator.
at line 340
PendingRequest
authenticate(Authenticator $authenticator)
Authenticate the pending request.
The authenticator is applied immediately, except while plugins boot: it is then applied once every plugin has booted.
in
AuthenticatesRequests at line 53
AuthenticatesRequests
withToken(string $token, string $type = 'Bearer')
Authenticate the request with a token.
in
AuthenticatesRequests at line 63
AuthenticatesRequests
withBasicAuth(string $username, string $password)
Authenticate the request with basic authentication.
in
AuthenticatesRequests at line 73
AuthenticatesRequests
withDigestAuth(string $username, string $password)
Authenticate the request with digest authentication.
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.
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.
in
HasBody at line 36
HasBody
withBody(mixed $content, string|null $contentType = 'application/json')
Set the raw request body.
in
HasBody at line 80
HasBody
asMultipart()
Use a multipart request body, keeping any existing multipart values.
in
HasBody at line 97
HasBody
attach(array|string $name, mixed $contents = '', string|null $filename = null, array $headers = [])
Attach a multipart value to the request.
in
HasBody at line 129
HasBody
withData(array $data)
Merge structured values into the request body.
A multipart body receives each value as an appended field.
in
HasBody at line 154
mixed
body()
Get the resolved request body value.
in
HasBody at line 162
bool
hasBody()
Determine if the request has a body repository.
in
HasBody at line 172
final BodyRepository|null
copyBodyRepository()
| internal |
Copy the body repository for a pending request.
in
HasBody at line 182
protected BodyRepository|null
defaultBodyRepository()
Resolve the default body repository.
in
HasBody at line 190
protected BodyRepository|null
bodyRepository()
Get the request body repository.
in
HasDebugging at line 22
HasDebugging
debugRequest(callable|null $onRequest = null, bool $die = false)
Debug the final application-owned request.
in
HasDebugging at line 50
HasDebugging
debugResponse(callable|null $onResponse = null, bool $die = false)
Debug the response before ordinary response middleware.
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.
in
HasCookies at line 25
HasCookies
withCookie(SetCookie $cookie)
Specify a cookie and its attributes for the request.
in
HasCookies at line 46
HasCookies
withCookies(array $cookies, string $domain)
Specify cookies that should be included with the request.
in
HasCookies at line 60
array
cookies()
Get the request cookies and their attributes.
in
HasDelay at line 21
HasDelay
delay(int $milliseconds)
Delay the request by the given milliseconds.
in
HasDelay at line 35
int|null
delayMilliseconds()
Get the request delay in milliseconds.
in
HasDelay at line 43
protected int|null
defaultDelay()
Resolve the default request delay.
in
HasHeaders at line 21
array
headers()
Get the request headers.
in
HasHeaders at line 29
bool
hasHeader(string $name)
Determine if the request contains the given header.
at line 478
PendingRequest
withHeaders(array $headers)
Add headers to the request.
in
HasHeaders at line 58
HasHeaders
withHeader(string $name, mixed $value)
Add a header to the request.
at line 492
PendingRequest
replaceHeaders(array $headers)
Replace matching headers on the request.
in
HasHeaders at line 97
HasHeaders
withoutHeader(string $name)
Remove a header from the request.
in
HasHeaders at line 108
HasHeaders
withoutHeaders(array $names)
Remove the given headers from the request.
in
HasHeaders at line 126
HasHeaders
contentType(string $contentType)
Specify the request content type.
in
HasHeaders at line 136
HasHeaders
acceptJson()
Indicate that JSON should be returned by the server.
in
HasHeaders at line 146
HasHeaders
accept(string $contentType)
Indicate the type of content that should be returned by the server.
in
HasHeaders at line 156
HasHeaders
withUserAgent(bool|string $userAgent)
Specify the request user agent.
in
HasHeaders at line 166
protected array
defaultHeaders()
Resolve the default request headers.
in
HasHeaders at line 174
protected ArrayRepository
headerRepository()
Get the request header repository.
in
HasMiddleware at line 19
MiddlewarePipeline
middleware()
Get the request middleware pipeline.
in
HasOptions at line 23
array
options()
Get the request options.
in
HasOptions at line 34
HasOptions
withOptions(array $options)
Add options to the request.
in
HasOptions at line 47
HasOptions
withoutOptions(array|string $keys)
Remove the given options from the request.
in
HasOptions at line 59
HasOptions
maxRedirects(int $max)
Specify the maximum number of redirects to allow.
in
HasOptions at line 77
HasOptions
withoutRedirecting()
Indicate that redirects should not be followed.
in
HasOptions at line 87
HasOptions
withoutVerifying()
Indicate that TLS certificates should not be verified.
in
HasOptions at line 98
HasOptions
sink(resource|StreamInterface|string $to)
Specify where the response body should be stored.
in
HasOptions at line 108
HasOptions
timeout(float|int $seconds)
Specify the request timeout in seconds.
in
HasOptions at line 118
HasOptions
connectTimeout(float|int $seconds)
Specify the connection timeout in seconds.
in
HasOptions at line 129
HasOptions
withTelescopeTags(array $tags)
Add Telescope tags to the request.
in
HasOptions at line 139
HasOptions
withoutTelescope()
Disable Telescope recording for the request.
in
HasOptions at line 149
protected array
defaultOptions()
Resolve the default request options.
in
HasOptions at line 157
protected ArrayRepository
optionRepository()
Get the request option repository.
in
HasQuery at line 24
string|null
queryString()
Get the raw query string override, without a leading question mark.
at line 325
PendingRequest
withQueryString(string $query)
Replace the raw query string and invalidate the finalized URI.
in
HasQuery at line 44
array
queryParameters()
Get the request query parameters.
at line 297
PendingRequest
withQueryParameters(array $parameters)
Add query parameters to the request.
at line 314
PendingRequest
withoutQueryParameters(array|string $keys)
Remove query parameters and invalidate the finalized URI.
Only values added through the query parameter methods are removed. Values embedded in the base URL, endpoint or raw query string are unchanged.
in
HasQuery at line 83
protected array
defaultQuery()
Resolve the default request query parameters.
in
HasQuery at line 91
protected string|null
defaultQueryString()
Resolve the default raw query string override.
in
HasQuery at line 99
protected ArrayRepository
queryRepository()
Get the request query repository.
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.
in
HasRetryPolicy at line 37
RetryPolicy|null
retryPolicy()
Get the request retry policy.
in
HasRetryPolicy at line 45
protected RetryPolicy|null
defaultRetryPolicy()
Resolve the default retry policy.
in
HasUrlParameters at line 21
array
urlParameters()
Get the parameters substituted into URL templates.
at line 247
PendingRequest
withUrlParameters(array $parameters = [])
Specify the URL parameters and invalidate the finalized URI.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 139
__construct(Connector $connector, Request $request)
Create a side-effect-free pending request.
at line 185
Connector
connector()
Get the connector.
at line 195
Request
request()
Get the request.
at line 203
Method
method()
Get the HTTP method.
at line 213
PendingRequest
withMethod(Method $method)
Change the HTTP method used by the operation.
at line 223
string|null
url()
Get the absolute URL override.
at line 233
PendingRequest
withUrl(string $url)
Replace the connector base URL and request endpoint for this operation.
at line 258
UriInterface
uri()
Get the final request URI.
at line 284
PendingRequest
finalizeUri()
| internal |
Finalize the request URI after ordinary request middleware.
at line 358
PendingRequest
applyAuthentication()
| internal |
Apply the selected authenticator.
at line 370
protected void
setAuthentication(Authenticator $authenticator)
Apply an authenticator while recording its header writes.
at line 387
PendingRequest
bootPlugins()
| internal |
Boot the connector and request plugins.
at line 405
PendingRequest
mergeMiddleware(MiddlewarePipeline $middleware)
| internal |
Merge global or request middleware into this operation's own pipeline.
at line 417
PendingRequest
executeRequestPipeline()
| internal |
Execute the request middleware pipeline.
at line 427
Response
executeResponsePipeline(Response $response)
Execute the response middleware pipeline.
at line 435
void
executeFatalPipeline(FatalRequestException $exception)
Execute the fatal exception middleware pipeline.
at line 445
PendingRequest
prepareBody()
| internal |
Prepare the request body after ordinary request middleware.
at line 467
StreamInterface|null
preparedBody()
| internal |
Get the prepared request body.
at line 505
protected void
recordAuthenticationHeaders(array $headers)
Record headers written during authentication, including unchanged values.
at line 520
array
authenticationHeaderNames()
| internal |
Get the authentication header names.
at line 531
PendingRequest
setTransportAuthentication(array $authentication)
Set the dedicated transport authentication option.
at line 543
array|null
transportAuthentication()
Get the dedicated transport authentication option.
at line 553
PendingRequest
setCertificate(string $path, string|null $password = null)
Set the client certificate option.
at line 565
array|string|null
certificate()
Get the client certificate option.
at line 577
PendingRequest
observePsrRequest(callable $observer)
| internal |
Observe the final application-owned PSR request.
at line 587
RequestInterface
handlePsrRequest(RequestInterface $request)
Apply the connector and request PSR hooks.
at line 599
void
notifyPsrRequestObservers(RequestInterface $request)
| internal |
Notify the final PSR request observers.
at line 611
RequestInterface
createPsrRequest()
| internal |
Create the logical PSR request for a short-circuit response.
at line 638
PendingRequest
setPsrRequest(RequestInterface $request)
| internal |
Set the final application-owned PSR request.
at line 653
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.
at line 684
bool
restoreAttemptBody()
| internal |
Restore the attempt body before another attempt.
at line 709
PendingRequest
setFakeResponse(FakeResponse|null $fakeResponse)
Set the fake response.
at line 719
FakeResponse|null
fakeResponse()
Get the fake response.
at line 734
PendingRequest
validateCachingConfiguration()
| internal |
Validate the request's caching configuration.
at line 751
bool
isCacheable()
| internal |
Determine if this operation is cacheable.
at line 766
bool
shouldInvalidateCache()
| internal |
Determine if the matching cache entry should be invalidated.
at line 776
DateInterval|DateTimeInterface|int
cacheFor()
| internal |
Get the cache duration.
at line 787
UnitEnum|string|null
cacheStore()
| internal |
Get the selected cache store.
at line 803
string|null
resolveCacheKey()
| internal |
Resolve the custom cache key.
at line 812
protected Cacheable|null
cacheableResource()
Resolve the request or connector that owns cache duration and storage.
at line 827
Response
createResponse(Response $response, RequestInterface $request)
| internal |
Create the response selected by this operation.
at line 842
string|null
resolveResponseClass(Response $response)
Resolve the custom response class.
at line 857
protected int|null
streamOffset(StreamInterface|null $stream)
Get the current offset of a seekable stream.
at line 865
protected string|null
multipartContentType()
Resolve the multipart content type unless the caller provided one with a boundary.
at line 887
static void
flushState()
Flush all static state.