PendingRequest
class PendingRequest
Traits
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 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 Closure|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 | $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 Collection | $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 bool | $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
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new HTTP Client instance.
Set the base URL for the pending request.
Attach a raw body to the request.
Indicate the request contains JSON.
Indicate the request contains form parameters.
Attach a file to the request.
Indicate the request is a multi-part form request.
Specify the body format of the request.
Set the given query parameters in the request URI.
Specify the request's content type.
Indicate that JSON should be returned by the server.
Indicate the type of content that should be returned by the server.
Add the given headers to the request.
Add the given header to the request.
Replace the given headers on the request.
Specify the basic authentication username and password for the request.
Specify the digest authentication username and password for the request.
Specify the NTLM authentication username and password for the request.
Specify an authorization token for the request.
Specify the user agent for the request.
Specify the URL parameters that can be substituted into the request URL.
Specify the cookies that should be included with the request.
Specify the maximum number of redirects to allow.
Indicate that redirects should not be followed.
Indicate that TLS certificates should not be verified.
Specify the path where the body of the response should be stored.
Specify the timeout (in seconds) for the request.
Specify the connect timeout (in seconds) for the request.
Replace the specified options on the request.
Add new middleware the client handler stack.
Add new request middleware the client handler stack.
Add new response middleware the client handler stack.
Set arbitrary attributes to store with the request.
Indicate that Telescope should not record this request.
Set Telescope tags for this request.
Add a new "before sending" callback to the request.
Add a new callback to execute after the response is built.
Throw an exception if a server or client error occurs.
Throw an exception if a server or client error occurred and the given condition evaluates to true.
Throw an exception if a server or client error occurred and the given condition evaluates to false.
Dump the request before sending.
Dump the request before sending and end the script.
Issue a GET request to the given URL.
Issue a HEAD request to the given URL.
Issue a PATCH request to the given URL.
Issue a DELETE request to the given URL.
Send the request to the given URL.
Substitute the URL parameters in the given URL.
Parse the given HTTP options and set the appropriate additional options.
Parse multi-part form data.
Send an asynchronous request to the given URL.
Handle the response of an asynchronous request.
Get the maximum number of attempts for the request.
Get the delay in milliseconds before the next retry attempt.
Send a request either synchronously or asynchronously.
Get the request data as an array so that we can attach it to the request for convenient assertions.
Normalize the given request options.
Normalize the given header values.
Normalize the given header value.
Normalize non-finite floats within a nested array.
Normalize the given multipart option.
Normalize the given multipart headers.
Normalize the given request option value.
Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.
Ensure the given request body can be passed to Guzzle.
Build the Guzzle client.
Determine if a reusable client is required.
Retrieve a reusable Guzzle client.
Build the Guzzle client handler stack.
Add the necessary handlers to the given handler stack.
Build the before sending handler.
Build the recorder handler.
Build the stub handler.
Get the sink stub handler callback.
Execute the "before sending" callbacks.
Replace the given options with the current request options.
Create a new response instance using the given PSR response.
Register a stub callable that will intercept requests and be able to return stub responses.
Indicate that an exception should be thrown if any request is not faked.
Allow stray, unfaked requests for specific URL patterns.
Determine if the given URL is allowed as a stray request.
Toggle asynchronicity in requests.
Retrieve the pending request promise.
Dispatch the RequestSending event if a dispatcher is available.
Dispatch the ResponseReceived event if a dispatcher is available.
Dispatch the ConnectionFailed event if a dispatcher is available.
Indicate that request exceptions should be truncated to the given length.
Indicate that request exceptions should not be truncated.
Handle the given connection exception.
Handle the given request exception with no response.
Handle the given request exception with a response.
Set the client instance.
Create a new client instance using the given handler.
Get the pending request options.
Set the pending request connection.
Get the pending request connection.
No description
Get the effective request-option preset for the selected connection.
Merge HTTP option layers using the request-option merge rules.
Reject options whose ownership belongs to dedicated APIs.
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.
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
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.
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.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
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.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 214
__construct(Factory|null $factory = null, array $middleware = [], array $options = [])
Create a new HTTP Client instance.
at line 247
PendingRequest
baseUrl(string $url)
Set the base URL for the pending request.
at line 261
PendingRequest
withBody(mixed $content, string $contentType = 'application/json')
Attach a raw body to the request.
at line 279
PendingRequest
asJson()
Indicate the request contains JSON.
at line 287
PendingRequest
asForm()
Indicate the request contains form parameters.
at line 297
PendingRequest
attach(array|string $name, resource|string $contents = '', string|null $filename = null, array $headers = [])
Attach a file to the request.
at line 326
PendingRequest
asMultipart()
Indicate the request is a multi-part form request.
at line 334
PendingRequest
bodyFormat(string $format)
Specify the body format of the request.
at line 344
PendingRequest
withQueryParameters(array $parameters)
Set the given query parameters in the request URI.
at line 356
PendingRequest
contentType(string $contentType)
Specify the request's content type.
at line 366
PendingRequest
acceptJson()
Indicate that JSON should be returned by the server.
at line 374
PendingRequest
accept(string $contentType)
Indicate the type of content that should be returned by the server.
at line 382
PendingRequest
withHeaders(array $headers)
Add the given headers to the request.
at line 394
PendingRequest
withHeader(string $name, mixed $value)
Add the given header to the request.
at line 402
PendingRequest
replaceHeaders(array $headers)
Replace the given headers on the request.
at line 412
PendingRequest
withBasicAuth(string $username, string $password)
Specify the basic authentication username and password for the request.
at line 422
PendingRequest
withDigestAuth(string $username, string $password)
Specify the digest authentication username and password for the request.
at line 432
PendingRequest
withNtlmAuth(string $username, string $password)
Specify the NTLM authentication username and password for the request.
at line 442
PendingRequest
withToken(string $token, string $type = 'Bearer')
Specify an authorization token for the request.
at line 452
PendingRequest
withUserAgent(bool|string $userAgent)
Specify the user agent for the request.
at line 462
PendingRequest
withUrlParameters(array $parameters = [])
Specify the URL parameters that can be substituted into the request URL.
at line 472
PendingRequest
withCookies(array $cookies, string $domain)
Specify the cookies that should be included with the request.
at line 484
PendingRequest
maxRedirects(int $max)
Specify the maximum number of redirects to allow.
at line 494
PendingRequest
withoutRedirecting()
Indicate that redirects should not be followed.
at line 504
PendingRequest
withoutVerifying()
Indicate that TLS certificates should not be verified.
at line 516
PendingRequest
sink(resource|string $to)
Specify the path where the body of the response should be stored.
at line 526
PendingRequest
timeout(float|int $seconds)
Specify the timeout (in seconds) for the request.
at line 536
PendingRequest
connectTimeout(float|int $seconds)
Specify the connect timeout (in seconds) for the request.
at line 546
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.
at line 563
PendingRequest
withOptions(array $options)
Replace the specified options on the request.
at line 574
PendingRequest
withMiddleware(callable $middleware)
Add new middleware the client handler stack.
at line 584
PendingRequest
withRequestMiddleware(callable $middleware)
Add new request middleware the client handler stack.
at line 594
PendingRequest
withResponseMiddleware(callable $middleware)
Add new response middleware the client handler stack.
at line 604
PendingRequest
withAttributes(array $attributes)
Set arbitrary attributes to store with the request.
at line 614
PendingRequest
withoutTelescope()
Indicate that Telescope should not record this request.
at line 624
PendingRequest
withTelescopeTags(array $tags)
Set Telescope tags for this request.
at line 632
PendingRequest
beforeSending(callable $callback)
Add a new "before sending" callback to the request.
at line 642
PendingRequest
afterResponse(callable $callback)
Add a new callback to execute after the response is built.
at line 652
PendingRequest
throw(callable|null $callback = null)
Throw an exception if a server or client error occurs.
at line 662
PendingRequest
throwIf(bool|callable $condition)
Throw an exception if a server or client error occurred and the given condition evaluates to true.
at line 674
PendingRequest
throwUnless(bool|callable $condition)
Throw an exception if a server or client error occurred and the given condition evaluates to false.
at line 682
PendingRequest
dump()
Dump the request before sending.
at line 696
PendingRequest
dd()
Dump the request before sending and end the script.
at line 714
PromiseInterface|Response
get(string $url, Arrayable|array|JsonSerializable|string|null $query = null)
Issue a GET request to the given URL.
at line 730
PromiseInterface|Response
head(string $url, array|string|null $query = null)
Issue a HEAD request to the given URL.
at line 746
PromiseInterface|Response
post(string $url, array|JsonSerializable $data = [])
Issue a POST request to the given URL.
at line 758
PromiseInterface|Response
patch(string $url, array $data = [])
Issue a PATCH request to the given URL.
at line 770
PromiseInterface|Response
put(string $url, array $data = [])
Issue a PUT request to the given URL.
at line 782
PromiseInterface|Response
delete(string $url, array $data = [])
Issue a DELETE request to the given URL.
at line 804
PromiseInterface|Response
send(string $method, string $url, array $options = [])
Send the request to the given URL.
at line 897
protected string
expandUrlParameters(string $url)
Substitute the URL parameters in the given URL.
at line 905
protected array
parseHttpOptions(array $options)
Parse the given HTTP options and set the appropriate additional options.
at line 938
protected array
parseMultipartBodyFormat(array $data)
Parse multi-part form data.
at line 958
protected PromiseInterface
makePromise(string $method, string $url, array $options = [], int $attempt = 1)
Send an asynchronous request to the given URL.
at line 1006
protected mixed
handlePromiseResponse(Response|Throwable $response, string $method, string $url, array $options, int $attempt)
Handle the response of an asynchronous request.
at line 1059
protected int
getMaximumAttempts()
Get the maximum number of attempts for the request.
at line 1069
protected int|float
retryDelayInMilliseconds(int $attempt, mixed $exception)
Get the delay in milliseconds before the next retry attempt.
at line 1081
protected PromiseInterface|ResponseInterface
sendRequest(string $method, string $url, array $options = [])
Send a request either synchronously or asynchronously.
at line 1105
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.
at line 1137
protected array
normalizeRequestOptions(array $options)
Normalize the given request options.
at line 1177
protected array
normalizeHeaderValues(array $headers)
Normalize the given header values.
at line 1191
protected string|array
normalizeHeaderValue(mixed $value)
Normalize the given header value.
at line 1221
protected array
normalizeNonFiniteFloatValues(array $values)
Normalize non-finite floats within a nested array.
at line 1237
protected array
normalizeMultipartOption(array $multipart)
Normalize the given multipart option.
at line 1273
protected array
normalizeMultipartHeaders(array $multipart)
Normalize the given multipart headers.
at line 1295
protected mixed
normalizeRequestOptionValue(mixed $value)
Normalize the given request option value.
at line 1309
protected string
normalizeScalarString(bool|float|int|string $value)
Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.
at line 1327
protected void
ensureValidRequestBody(mixed $body)
Ensure the given request body can be passed to Guzzle.
at line 1337
protected Response
populateResponse(Response $response)
Populate the given response with additional data.
at line 1349
ClientInterface
buildClient()
Build the Guzzle client.
at line 1366
protected bool
requestsReusableClient()
Determine if a reusable client is required.
at line 1374
protected ClientInterface
getReusableClient()
Retrieve a reusable Guzzle client.
at line 1382
HandlerStack
buildHandlerStack()
Build the Guzzle client handler stack.
at line 1396
HandlerStack
pushHandlers(HandlerStack $handlerStack)
Add the necessary handlers to the given handler stack.
at line 1412
Closure
buildBeforeSendingHandler()
Build the before sending handler.
at line 1424
Closure
buildRecorderHandler()
Build the recorder handler.
at line 1447
Closure
buildStubHandler()
Build the stub handler.
at line 1483
protected Closure
sinkStubHandler(resource|string $sink)
Get the sink stub handler callback.
at line 1502
RequestInterface
runBeforeSendingCallbacks(RequestInterface $request, array $options)
Execute the "before sending" callbacks.
at line 1527
array
mergeOptions(...$options)
Replace the given options with the current request options.
at line 1548
protected Response
newResponse(PromiseInterface|ResponseInterface $response)
Create a new response instance using the given PSR response.
at line 1564
protected Response
runAfterResponseCallbacks(Response $response)
Execute the "after response" callbacks.
at line 1580
PendingRequest
stub(callable|Collection $callback)
Register a stub callable that will intercept requests and be able to return stub responses.
at line 1592
PendingRequest
preventStrayRequests(bool $prevent = true)
Indicate that an exception should be thrown if any request is not faked.
at line 1602
PendingRequest
allowStrayRequests(array $only)
Allow stray, unfaked requests for specific URL patterns.
at line 1612
bool
isAllowedRequestUrl(string $url)
Determine if the given URL is allowed as a stray request.
at line 1630
PendingRequest
async(bool $async = true)
Toggle asynchronicity in requests.
at line 1640
PromiseInterface|null
getPromise()
Retrieve the pending request promise.
at line 1648
protected void
dispatchRequestSendingEvent()
Dispatch the RequestSending event if a dispatcher is available.
at line 1658
protected void
dispatchResponseReceivedEvent(Response $response)
Dispatch the ResponseReceived event if a dispatcher is available.
at line 1670
protected void
dispatchConnectionFailedEvent(Request $request, ConnectionException $exception)
Dispatch the ConnectionFailed event if a dispatcher is available.
at line 1680
PendingRequest
truncateExceptionsAt(int $length)
Indicate that request exceptions should be truncated to the given length.
at line 1690
PendingRequest
dontTruncateExceptions()
Indicate that request exceptions should not be truncated.
at line 1702
protected void
marshalConnectionException(ConnectException $e)
Handle the given connection exception.
at line 1720
protected void
marshalRequestExceptionWithoutResponse(RequestException $e)
Handle the given request exception with no response.
at line 1739
protected void
marshalRequestExceptionWithResponse(RequestException $e)
Handle the given request exception with a response.
at line 1754
PendingRequest
setClient(ClientInterface $client)
Set the client instance.
at line 1764
PendingRequest
setHandler(callable $handler)
Create a new client instance using the given handler.
at line 1774
array
getOptions()
Get the pending request options.
at line 1786
PendingRequest
connection(string $connection, array|null $config = null)
Set the pending request connection.
at line 1805
string|null
getConnection()
Get the pending request connection.
at line 1810
array|null
getConnectionConfig()
No description
at line 1818
protected array
connectionOptions()
Get the effective request-option preset for the selected connection.
at line 1834
protected array
mergeOptionLayers(array ...$layers)
Merge HTTP option layers using the request-option merge rules.
at line 1853
protected void
validateRequestOptions(array $options, string $source)
Reject options whose ownership belongs to dedicated APIs.
at line 1861
static void
flushState()
Flush all static state.