class PendingRequest implements Transient

Traits

Constants

DATA_OPTION

PRIOR_SENDS_OPTION

protected PREPARED_BODY_OPTION

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected ClientInterface|null $client

The Guzzle client instance.

protected callable $handler

The Guzzle HTTP handler.

protected string $baseUrl

The base URL for the request.

protected array $urlParameters

The parameters that can be substituted into the URL.

protected string $bodyFormat

The request body format.

protected null|resource|StreamInterface|string $pendingBody

The raw body for the request.

protected array $pendingFiles

The pending files for the request.

protected CookieJar $cookies

The request cookies.

protected TransferStats|null $transferStats

The transfer stats for the request.

protected int $sendCount

The number of physical requests started during the current logical send.

protected array $options

The request options.

protected array $baseOptions

The factory-level options applied below connection and request options.

protected Closure|null $throwCallback

A callback to run when throwing if a server or client error occurs.

protected Closure|null $throwIfCallback

A callback to check if an exception should be thrown when a server or client error occurs.

protected array|int $tries

The number of times to try the request.

protected Throwable): int|int $retryDelay

The number of milliseconds to wait between retries.

protected bool $retryThrow

Whether to throw an exception when all retries fail.

protected null|callable(null|Throwable, static, null|string): bool $retryWhenCallback

The callback that will determine if the request should be retried.

protected Collection $beforeSendingCallbacks

The callbacks that should execute before the request is sent.

protected Response, null|Request): mixed> $afterResponseCallbacks

The callbacks that should execute after the response is built.

protected Collection|null $stubCallbacks

The stub callables that will handle requests.

protected bool $preventStrayRequests

Indicates that an exception should be thrown if any request is not faked.

protected array $allowedStrayRequestUrls

The URL patterns that are allowed as stray requests.

protected Collection $middleware

The middleware callables added by users that will handle requests.

protected TAsync $async

Whether the requests should be asynchronous.

protected array $attributes

The attributes to track with the request.

protected PromiseInterface|null $promise

The pending request promise.

protected Request|null $request

The sent request object, if a request has been made.

protected string|null $connection

The current connection name for the pending request.

protected array|null $connectionConfig

The current connection configuration for the pending request.

protected array $mergeableOptions

The Guzzle request options that are mergeable via array_merge_recursive.

protected false|int|null $truncateExceptionsAt

The length at which request exceptions will be truncated.

Methods

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.

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(Factory|null $factory = null, array $middleware = [], array $options = [])

Create a new HTTP Client instance.

baseUrl(string $url)

Set the base URL for the pending request.

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

Attach a raw body to the request.

asJson()

Indicate the request contains JSON.

asForm()

Indicate the request contains form parameters.

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

Attach a file to the request.

asMultipart()

Indicate the request is a multi-part form request.

bodyFormat(string $format)

Specify the body format of the request.

withQueryParameters(array $parameters)

Set the given query parameters in the request URI.

contentType(string $contentType)

Specify the request's 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.

withHeaders(array $headers)

Add the given headers to the request.

withHeader(string $name, mixed $value)

Add the given header to the request.

replaceHeaders(array $headers)

Replace the given headers on the request.

withBasicAuth(string $username, string $password)

Specify the basic authentication username and password for the request.

withDigestAuth(string $username, string $password)

Specify the digest authentication username and password for the request.

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

Specify an authorization token for the request.

withUserAgent(bool|string $userAgent)

Specify the user agent for the request.

withUrlParameters(array $parameters = [])

Specify the URL parameters that can be substituted into the request URL.

withCookie(SetCookie $cookie)

Specify a cookie and its attributes for the request.

withCookies(array $cookies, string $domain)

Specify the cookies that should be included with 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 the path where the body of the response should be stored.

timeout(float|int $seconds)

Specify the timeout (in seconds) for the request.

connectTimeout(float|int $seconds)

Specify the connect timeout (in seconds) for the request.

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.

withOptions(array $options)

Replace the specified options on the request.

withMiddleware(callable $middleware)

Add new middleware the client handler stack.

prependMiddleware(callable $middleware)

Prepend new middleware to the client handler stack.

withRequestMiddleware(callable $middleware)

Add new request middleware the client handler stack.

withResponseMiddleware(callable $middleware)

Add new response middleware the client handler stack.

withAttributes(array $attributes)

Set arbitrary attributes to store with the request.

array
attributes()

Get the attributes stored with the request.

withoutTelescope()

Indicate that Telescope should not record this request.

withTelescopeTags(array $tags)

Set Telescope tags for this request.

beforeSending(callable $callback)

Add a new "before sending" callback to the request.

afterResponse(callable $callback)

Add a new callback to execute after the response is built.

throw(callable|null $callback = null)

Throw an exception if a server or client error occurs.

throwIf(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to true.

throwUnless(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to false.

dump()

Dump the request before sending.

dd()

Dump the request before sending and end the script.

PromiseInterface|Response
get(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a GET request to the given URL.

PromiseInterface|Response
head(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a HEAD request to the given URL.

PromiseInterface|Response
query(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a QUERY request to the given URL.

PromiseInterface|Response
post(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a POST request to the given URL.

PromiseInterface|Response
patch(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PATCH request to the given URL.

PromiseInterface|Response
put(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PUT request to the given URL.

PromiseInterface|Response
delete(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a DELETE request to the given URL.

PromiseInterface|Response
send(string $method, string $url, array $options = [])

Send the request to the given URL.

string
expandUrlParameters(string $url)

Substitute the URL parameters in the given URL.

array
parseHttpOptions(array $options)

Parse the given HTTP options and set the appropriate additional options.

array
parseMultipartBodyFormat(array $data)

Parse multi-part form data.

PromiseInterface
makePromise(string $method, string $url, array $options = [], int $attempt = 1)

Send an asynchronous request to the given URL.

mixed
handlePromiseResponse(Response|Throwable $response, string $method, string $url, array $options, int $attempt)

Handle the response of an asynchronous request.

int
getMaximumAttempts()

Get the maximum number of attempts for the request.

int|float
retryDelayInMilliseconds(int $attempt, mixed $exception)

Get the delay in milliseconds before the next retry attempt.

PromiseInterface|ResponseInterface
sendRequest(string $method, string $url, array $options = [])

Send a request either synchronously or asynchronously.

array
parseRequestData(string $method, string $url, array $options)

Get the request data as an array so that we can attach it to the request for convenient assertions.

array
normalizeRequestOptions(array $options)

Normalize the given request options.

array
normalizeHeaderValues(array $headers)

Normalize the given header values.

string|array
normalizeHeaderValue(mixed $value)

Normalize the given header value.

array
normalizeNonFiniteFloatValues(array $values)

Normalize non-finite floats within a nested array.

array
normalizeMultipartOption(array $multipart)

Normalize the given multipart option.

array
normalizeMultipartHeaders(array $multipart)

Normalize the given multipart headers.

mixed
normalizeRequestOptionValue(mixed $value)

Normalize the given request option value.

array|string|null
normalizeQuery(mixed $query)

Normalize a query supplied to a GET request.

mixed
normalizeStructuredDataValue(mixed $value)

Normalize nested structured data values.

string
normalizeScalarString(bool|float|int|string $value)

Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.

void
ensureValidRequestBody(mixed $body)

Ensure the given request body can be passed to Guzzle.

populateResponse(Response $response)

Populate the given response with additional data.

ClientInterface
buildClient()

Build the Guzzle client.

bool
requestsReusableClient()

Determine if a reusable client is required.

ClientInterface
getReusableClient()

Retrieve a reusable Guzzle client.

ClientInterface
createClient(HandlerStack $handlerStack)

Create a new Guzzle client.

HandlerStack
buildHandlerStack()

Build the Guzzle client handler stack.

HandlerStack
pushHandlers(HandlerStack $handlerStack)

Add the necessary handlers to the given handler stack.

buildPreparedBodyHandler()

Build the prepared body tracking handler.

buildBeforeSendingHandler()

Build the before sending handler.

buildRecorderHandler()

Build the recorder handler.

buildStubHandler()

Build the stub handler.

sinkStubHandler(mixed $sink)

Get the sink stub handler callback.

RequestInterface
runBeforeSendingCallbacks(RequestInterface $request, array $options)

Execute the "before sending" callbacks.

array
mergeOptions(...$options)

Replace the given options with the current request options.

newResponse(ResponseInterface $response)

Create a new response instance using the given PSR response.

runAfterResponseCallbacks(Response $response)

Execute the "after response" callbacks.

stub(callable|Collection $callback)

Register a stub callable that will intercept requests and be able to return stub responses.

preventStrayRequests(bool $prevent = true)

Indicate that an exception should be thrown if any request is not faked.

allowStrayRequests(array $only)

Allow stray, unfaked requests for specific URL patterns.

bool
isAllowedRequestUrl(string $url)

Determine if the given URL is allowed as a stray request.

async(bool $async = true)

Toggle asynchronicity in requests.

PromiseInterface|null
getPromise()

Retrieve the pending request promise.

void
dispatchRequestSendingEvent()

Dispatch the RequestSending event if a dispatcher is available.

void
dispatchResponseReceivedEvent(Response $response)

Dispatch the ResponseReceived event if a dispatcher is available.

void
dispatchConnectionFailedEvent(Request $request, ConnectionException $exception)

Dispatch the ConnectionFailed event if a dispatcher is available.

truncateExceptionsAt(int $length)

Indicate that request exceptions should be truncated to the given length.

dontTruncateExceptions()

Indicate that request exceptions should not be truncated.

ResponseInterface|null
responseFromException(Throwable $e)

Get the PSR-7 response carried by the given exception, if any.

void
marshalTransportException(TransferException $e)

Handle the given transport exception.

void
marshalTransportExceptionWithResponse(TransferException $e, ResponseInterface $response)

Handle the given transport exception that carried a response.

setClient(ClientInterface $client)

Set the client instance.

setHandler(callable $handler)

Create a new client instance using the given handler.

array
getOptions()

Get the pending request options.

connection(string $connection, array|null $config = null)

Set the pending request connection.

string|null
getConnection()

Get the pending request connection.

array|null
getConnectionConfig()

Get the pending request connection configuration.

array
connectionOptions()

Get the effective request-option preset for the selected connection.

array
mergeOptionLayers(array ...$layers)

Merge HTTP option layers using the request-option merge rules.

void
validateRequestOptions(array $options, string $source)

Reject options whose ownership belongs to dedicated APIs.

static void
flushState()

Flush all static state.

Details

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 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 241
__construct(Factory|null $factory = null, array $middleware = [], array $options = [])

Create a new HTTP Client instance.

Parameters

Factory|null $factory
array $middleware
array $options

at line 275
PendingRequest baseUrl(string $url)

Set the base URL for the pending request.

Parameters

string $url

Return Value

PendingRequest

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

Attach a raw body to the request.

Parameters

mixed $content
string|null $contentType

Return Value

PendingRequest

Exceptions

InvalidArgumentException

at line 309
PendingRequest asJson()

Indicate the request contains JSON.

Return Value

PendingRequest

at line 317
PendingRequest asForm()

Indicate the request contains form parameters.

Return Value

PendingRequest

at line 327
PendingRequest attach(array|string $name, resource|string $contents = '', string|null $filename = null, array $headers = [])

Attach a file to the request.

Parameters

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

Return Value

PendingRequest

at line 361
PendingRequest asMultipart()

Indicate the request is a multi-part form request.

Return Value

PendingRequest

at line 369
PendingRequest bodyFormat(string $format)

Specify the body format of the request.

Parameters

string $format

Return Value

PendingRequest

at line 379
PendingRequest withQueryParameters(array $parameters)

Set the given query parameters in the request URI.

Parameters

array $parameters

Return Value

PendingRequest

at line 391
PendingRequest contentType(string $contentType)

Specify the request's content type.

Parameters

string $contentType

Return Value

PendingRequest

at line 401
PendingRequest acceptJson()

Indicate that JSON should be returned by the server.

Return Value

PendingRequest

at line 409
PendingRequest accept(string $contentType)

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

Parameters

string $contentType

Return Value

PendingRequest

at line 417
PendingRequest withHeaders(array $headers)

Add the given headers to the request.

Parameters

array $headers

Return Value

PendingRequest

at line 429
PendingRequest withHeader(string $name, mixed $value)

Add the given header to the request.

Parameters

string $name
mixed $value

Return Value

PendingRequest

at line 437
PendingRequest replaceHeaders(array $headers)

Replace the given headers on the request.

Parameters

array $headers

Return Value

PendingRequest

at line 447
PendingRequest withBasicAuth(string $username, string $password)

Specify the basic authentication username and password for the request.

Parameters

string $username
string $password

Return Value

PendingRequest

at line 457
PendingRequest withDigestAuth(string $username, string $password)

Specify the digest authentication username and password for the request.

Parameters

string $username
string $password

Return Value

PendingRequest

at line 469
PendingRequest withToken(string $token, string $type = 'Bearer')

Specify an authorization token for the request.

Parameters

string $token
string $type

Return Value

PendingRequest

at line 479
PendingRequest withUserAgent(bool|string $userAgent)

Specify the user agent for the request.

Parameters

bool|string $userAgent

Return Value

PendingRequest

at line 489
PendingRequest withUrlParameters(array $parameters = [])

Specify the URL parameters that can be substituted into the request URL.

Parameters

array $parameters

Return Value

PendingRequest

at line 500
PendingRequest withCookie(SetCookie $cookie)

Specify a cookie and its attributes for the request.

Parameters

SetCookie $cookie

Return Value

PendingRequest

at line 518
PendingRequest withCookies(array $cookies, string $domain)

Specify the cookies that should be included with the request.

Parameters

array $cookies
string $domain

Return Value

PendingRequest

at line 530
PendingRequest maxRedirects(int $max)

Specify the maximum number of redirects to allow.

Parameters

int $max

Return Value

PendingRequest

at line 546
PendingRequest withoutRedirecting()

Indicate that redirects should not be followed.

Return Value

PendingRequest

at line 556
PendingRequest withoutVerifying()

Indicate that TLS certificates should not be verified.

Return Value

PendingRequest

at line 568
PendingRequest sink(resource|StreamInterface|string $to)

Specify the path where the body of the response should be stored.

Parameters

resource|StreamInterface|string $to

Return Value

PendingRequest

at line 578
PendingRequest timeout(float|int $seconds)

Specify the timeout (in seconds) for the request.

Parameters

float|int $seconds

Return Value

PendingRequest

at line 588
PendingRequest connectTimeout(float|int $seconds)

Specify the connect timeout (in seconds) for the request.

Parameters

float|int $seconds

Return Value

PendingRequest

at line 601
PendingRequest 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

PendingRequest

at line 618
PendingRequest withOptions(array $options)

Replace the specified options on the request.

Parameters

array $options

Return Value

PendingRequest

at line 629
PendingRequest withMiddleware(callable $middleware)

Add new middleware the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 639
PendingRequest prependMiddleware(callable $middleware)

Prepend new middleware to the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 649
PendingRequest withRequestMiddleware(callable $middleware)

Add new request middleware the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 659
PendingRequest withResponseMiddleware(callable $middleware)

Add new response middleware the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 669
PendingRequest withAttributes(array $attributes)

Set arbitrary attributes to store with the request.

Parameters

array $attributes

Return Value

PendingRequest

at line 679
array attributes()

Get the attributes stored with the request.

Return Value

array

at line 687
PendingRequest withoutTelescope()

Indicate that Telescope should not record this request.

Return Value

PendingRequest

at line 697
PendingRequest withTelescopeTags(array $tags)

Set Telescope tags for this request.

Parameters

array $tags

Return Value

PendingRequest

at line 705
PendingRequest beforeSending(callable $callback)

Add a new "before sending" callback to the request.

Parameters

callable $callback

Return Value

PendingRequest

at line 717
PendingRequest afterResponse(callable $callback)

Add a new callback to execute after the response is built.

Parameters

callable $callback

Return Value

PendingRequest

at line 729
PendingRequest throw(callable|null $callback = null)

Throw an exception if a server or client error occurs.

Parameters

callable|null $callback

Return Value

PendingRequest

at line 741
PendingRequest throwIf(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to true.

Parameters

bool|callable $condition
callable|null $callback

Return Value

PendingRequest

at line 755
PendingRequest throwUnless(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to false.

Parameters

bool|callable $condition
callable|null $callback

Return Value

PendingRequest

at line 767
PendingRequest dump()

Dump the request before sending.

Return Value

PendingRequest

at line 781
PendingRequest dd()

Dump the request before sending and end the script.

Return Value

PendingRequest

at line 802
PromiseInterface|Response get(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a GET request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable|string|null $query

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
InvalidArgumentException

at line 821
PromiseInterface|Response head(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a HEAD request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable|string|null $query

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
InvalidArgumentException

at line 840
PromiseInterface|Response query(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a QUERY request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
InvalidArgumentException

at line 855
PromiseInterface|Response post(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a POST request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
InvalidArgumentException

at line 870
PromiseInterface|Response patch(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PATCH request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
InvalidArgumentException

at line 885
PromiseInterface|Response put(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PUT request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
InvalidArgumentException

at line 900
PromiseInterface|Response delete(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a DELETE request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
InvalidArgumentException

at line 925
PromiseInterface|Response send(string $method, string $url, array $options = [])

Send the request to the given URL.

Parameters

string $method
string $url
array $options

Return Value

PromiseInterface|Response

Exceptions

Exception
Throwable
InvalidArgumentException

at line 1019
protected string expandUrlParameters(string $url)

Substitute the URL parameters in the given URL.

Parameters

string $url

Return Value

string

at line 1033
protected array parseHttpOptions(array $options)

Parse the given HTTP options and set the appropriate additional options.

Parameters

array $options

Return Value

array

Exceptions

InvalidArgumentException

at line 1080
protected array parseMultipartBodyFormat(array $data)

Parse multi-part form data.

Parameters

array $data

Return Value

array

at line 1100
protected PromiseInterface makePromise(string $method, string $url, array $options = [], int $attempt = 1)

Send an asynchronous request to the given URL.

Parameters

string $method
string $url
array $options
int $attempt

Return Value

PromiseInterface

Exceptions

Exception

at line 1154
protected mixed handlePromiseResponse(Response|Throwable $response, string $method, string $url, array $options, int $attempt)

Handle the response of an asynchronous request.

Parameters

Response|Throwable $response
string $method
string $url
array $options
int $attempt

Return Value

mixed

Exceptions

Exception

at line 1214
protected int getMaximumAttempts()

Get the maximum number of attempts for the request.

Return Value

int

at line 1224
protected int|float retryDelayInMilliseconds(int $attempt, mixed $exception)

Get the delay in milliseconds before the next retry attempt.

Parameters

int $attempt
mixed $exception

Return Value

int|float

at line 1236
protected PromiseInterface|ResponseInterface sendRequest(string $method, string $url, array $options = [])

Send a request either synchronously or asynchronously.

Parameters

string $method
string $url
array $options

Return Value

PromiseInterface|ResponseInterface

Exceptions

Exception

at line 1268
protected array parseRequestData(string $method, string $url, array $options)

Get the request data as an array so that we can attach it to the request for convenient assertions.

Parameters

string $method
string $url
array $options

Return Value

array

at line 1300
protected array normalizeRequestOptions(array $options)

Normalize the given request options.

Parameters

array $options

Return Value

array

Exceptions

InvalidArgumentException

at line 1360
protected array normalizeHeaderValues(array $headers)

Normalize the given header values.

Parameters

array $headers

Return Value

array

at line 1378
protected string|array normalizeHeaderValue(mixed $value)

Normalize the given header value.

Parameters

mixed $value

Return Value

string|array

Exceptions

InvalidArgumentException

at line 1408
protected array normalizeNonFiniteFloatValues(array $values)

Normalize non-finite floats within a nested array.

Parameters

array $values

Return Value

array

at line 1424
protected array normalizeMultipartOption(array $multipart)

Normalize the given multipart option.

Parameters

array $multipart

Return Value

array

at line 1460
protected array normalizeMultipartHeaders(array $multipart)

Normalize the given multipart headers.

Parameters

array $multipart

Return Value

array

Exceptions

InvalidArgumentException

at line 1482
protected mixed normalizeRequestOptionValue(mixed $value)

Normalize the given request option value.

Parameters

mixed $value

Return Value

mixed

at line 1498
protected array|string|null normalizeQuery(mixed $query)

Normalize a query supplied to a GET request.

Parameters

mixed $query

Return Value

array|string|null

Exceptions

InvalidArgumentException

at line 1512
protected mixed normalizeStructuredDataValue(mixed $value)

Normalize nested structured data values.

Parameters

mixed $value

Return Value

mixed

at line 1526
protected string normalizeScalarString(bool|float|int|string $value)

Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.

Parameters

bool|float|int|string $value

Return Value

string

at line 1544
protected void ensureValidRequestBody(mixed $body)

Ensure the given request body can be passed to Guzzle.

Parameters

mixed $body

Return Value

void

Exceptions

InvalidArgumentException

at line 1554
protected Response populateResponse(Response $response)

Populate the given response with additional data.

Parameters

Response $response

Return Value

Response

at line 1566
ClientInterface buildClient()

Build the Guzzle client.

Return Value

ClientInterface

at line 1574
protected bool requestsReusableClient()

Determine if a reusable client is required.

Return Value

bool

at line 1582
protected ClientInterface getReusableClient()

Retrieve a reusable Guzzle client.

Return Value

ClientInterface

at line 1590
ClientInterface createClient(HandlerStack $handlerStack)

Create a new Guzzle client.

Parameters

HandlerStack $handlerStack

Return Value

ClientInterface

at line 1601
HandlerStack buildHandlerStack()

Build the Guzzle client handler stack.

Return Value

HandlerStack

at line 1628
HandlerStack pushHandlers(HandlerStack $handlerStack)

Add the necessary handlers to the given handler stack.

Parameters

HandlerStack $handlerStack

Return Value

HandlerStack

at line 1652
protected Closure buildPreparedBodyHandler()

Build the prepared body tracking handler.

Return Value

Closure

at line 1666
Closure buildBeforeSendingHandler()

Build the before sending handler.

Return Value

Closure

at line 1691
Closure buildRecorderHandler()

Build the recorder handler.

Return Value

Closure

at line 1730
Closure buildStubHandler()

Build the stub handler.

Return Value

Closure

Exceptions

StrayRequestException

at line 1766
protected Closure sinkStubHandler(mixed $sink)

Get the sink stub handler callback.

Parameters

mixed $sink

Return Value

Closure

at line 1823
RequestInterface runBeforeSendingCallbacks(RequestInterface $request, array $options)

Execute the "before sending" callbacks.

Parameters

RequestInterface $request
array $options

Return Value

RequestInterface

at line 1870
array mergeOptions(...$options)

Replace the given options with the current request options.

Parameters

...$options

Return Value

array

at line 1891
protected Response newResponse(ResponseInterface $response)

Create a new response instance using the given PSR response.

Parameters

ResponseInterface $response

Return Value

Response

at line 1907
protected Response runAfterResponseCallbacks(Response $response)

Execute the "after response" callbacks.

Parameters

Response $response

Return Value

Response

at line 1923
PendingRequest stub(callable|Collection $callback)

Register a stub callable that will intercept requests and be able to return stub responses.

Parameters

callable|Collection $callback

Return Value

PendingRequest

at line 1935
PendingRequest preventStrayRequests(bool $prevent = true)

Indicate that an exception should be thrown if any request is not faked.

Parameters

bool $prevent

Return Value

PendingRequest

at line 1945
PendingRequest allowStrayRequests(array $only)

Allow stray, unfaked requests for specific URL patterns.

Parameters

array $only

Return Value

PendingRequest

at line 1955
bool isAllowedRequestUrl(string $url)

Determine if the given URL is allowed as a stray request.

Parameters

string $url

Return Value

bool

at line 1981
PendingRequest async(bool $async = true)

Toggle asynchronicity in requests.

Parameters

bool $async

Return Value

PendingRequest

at line 1992
PromiseInterface|null getPromise()

Retrieve the pending request promise.

Return Value

PromiseInterface|null

at line 2000
protected void dispatchRequestSendingEvent()

Dispatch the RequestSending event if a dispatcher is available.

Return Value

void

at line 2010
protected void dispatchResponseReceivedEvent(Response $response)

Dispatch the ResponseReceived event if a dispatcher is available.

Parameters

Response $response

Return Value

void

at line 2022
protected void dispatchConnectionFailedEvent(Request $request, ConnectionException $exception)

Dispatch the ConnectionFailed event if a dispatcher is available.

Parameters

Request $request
ConnectionException $exception

Return Value

void

at line 2032
PendingRequest truncateExceptionsAt(int $length)

Indicate that request exceptions should be truncated to the given length.

Parameters

int $length

Return Value

PendingRequest

at line 2042
PendingRequest dontTruncateExceptions()

Indicate that request exceptions should not be truncated.

Return Value

PendingRequest

at line 2052
protected ResponseInterface|null responseFromException(Throwable $e)

Get the PSR-7 response carried by the given exception, if any.

Parameters

Throwable $e

Return Value

ResponseInterface|null

at line 2072
protected void marshalTransportException(TransferException $e)

Handle the given transport exception.

Parameters

TransferException $e

Return Value

void

Exceptions

ConnectionException

at line 2089
protected void marshalTransportExceptionWithResponse(TransferException $e, ResponseInterface $response)

Handle the given transport exception that carried a response.

Parameters

TransferException $e
ResponseInterface $response

Return Value

void

Exceptions

ConnectionException
RequestException

at line 2099
PendingRequest setClient(ClientInterface $client)

Set the client instance.

Parameters

ClientInterface $client

Return Value

PendingRequest

at line 2109
PendingRequest setHandler(callable $handler)

Create a new client instance using the given handler.

Parameters

callable $handler

Return Value

PendingRequest

at line 2119
array getOptions()

Get the pending request options.

Return Value

array

at line 2131
PendingRequest connection(string $connection, array|null $config = null)

Set the pending request connection.

Parameters

string $connection
array|null $config

Return Value

PendingRequest

at line 2150
string|null getConnection()

Get the pending request connection.

Return Value

string|null

at line 2158
array|null getConnectionConfig()

Get the pending request connection configuration.

Return Value

array|null

at line 2166
protected array connectionOptions()

Get the effective request-option preset for the selected connection.

Return Value

array

at line 2182
protected array mergeOptionLayers(array ...$layers)

Merge HTTP option layers using the request-option merge rules.

Parameters

array ...$layers

Return Value

array

at line 2201
protected void validateRequestOptions(array $options, string $source)

Reject options whose ownership belongs to dedicated APIs.

Parameters

array $options
string $source

Return Value

void

at line 2209
static void flushState()

Flush all static state.

Return Value

void