PendingRequest
class PendingRequest (View source)
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
protected Factory|null | $factory | The factory instance. |
|
protected Client | $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 StreamInterface|string | $pendingBody | The raw body for the request. |
|
protected array | $pendingFiles | The pending files for the request. |
|
protected array | $cookies | The request cookies. |
|
protected TransferStats | $transferStats | The transfer stats for the request. |
|
protected array | $options | The request options. |
|
protected Closure | $throwCallback | A callback to run when throwing if a server or client error occurs. |
|
protected Closure | $throwIfCallback | A callback to check if an exception should be thrown when a server or client error occurs. |
|
protected 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 callable|null | $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|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 Collection | $middleware | The middleware callables added by users that will handle requests. |
|
protected bool | $async | Whether the requests should be asynchronous. |
|
protected PromiseInterface | $promise | The pending request promise. |
|
protected Request|null | $request | The sent request object, if a request has been made. |
|
protected array | $mergeableOptions | The Guzzle request options that are mergeable via array_merge_recursive. |
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 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.
Specify the number of times the request should be attempted.
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.
Add a new "before sending" callback to the request.
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 POST request to the given URL.
Issue a PATCH request to the given URL.
Issue a DELETE request to the given URL.
Send a pool of asynchronous requests concurrently.
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.
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.
Build the Guzzle client.
Determine if a reusable client is required.
Retrieve a reusable Guzzle client.
Create new 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.
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.
Set the client instance.
Create a new client instance using the given handler.
Get the pending request options.
Details
$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
__construct(Factory|null $factory = null, array $middleware = [])
Create a new HTTP Client instance.
$this
withBody(StreamInterface|string $content, string $contentType = 'application/json')
Attach a raw body to the request.
$this
attach(string|array $name, string|resource $contents = '', string|null $filename = null, array $headers = [])
Attach a file to the request.
$this
accept(string $contentType)
Indicate the type of content that should be returned by the server.
$this
withBasicAuth(string $username, string $password)
Specify the basic authentication username and password for the request.
$this
withDigestAuth(string $username, string $password)
Specify the digest authentication username and password for the request.
$this
withToken(string $token, string $type = 'Bearer')
Specify an authorization token for the request.
$this
withUrlParameters(array $parameters = [])
Specify the URL parameters that can be substituted into the request URL.
$this
withCookies(array $cookies, string $domain)
Specify the cookies that should be included with the request.
$this
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.
$this
withRequestMiddleware(callable $middleware)
Add new request middleware the client handler stack.
$this
withResponseMiddleware(callable $middleware)
Add new response middleware the client handler stack.
$this
throwIf(callable|bool $condition)
Throw an exception if a server or client error occurred and the given condition evaluates to true.
$this
throwUnless(callable|bool $condition)
Throw an exception if a server or client error occurred and the given condition evaluates to false.
Response
post(string $url, array|JsonSerializable|Arrayable $data = [])
Issue a POST request to the given URL.
Response
patch(string $url, array|JsonSerializable|Arrayable $data = [])
Issue a PATCH request to the given URL.
Response
put(string $url, array|JsonSerializable|Arrayable $data = [])
Issue a PUT request to the given URL.
Response
delete(string $url, array|JsonSerializable|Arrayable $data = [])
Issue a DELETE request to the given URL.
protected array
parseHttpOptions(array $options)
Parse the given HTTP options and set the appropriate additional options.
protected PromiseInterface
makePromise(string $method, string $url, array $options = [], int $attempt = 1)
Send an asynchronous request to the given URL.
protected mixed
handlePromiseResponse(TransferException $response, string $method, string $url, array $options, int $attempt)
Handle the response of an asynchronous request.
protected MessageInterface|PromiseInterface
sendRequest(string $method, string $url, array $options = [])
Send a request either synchronously or asynchronously.
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.
protected Response
populateResponse(Response $response)
Populate the given response with additional data.
HandlerStack
pushHandlers(HandlerStack $handlerStack)
Add the necessary handlers to the given handler stack.
RequestInterface
runBeforeSendingCallbacks(RequestInterface $request, array $options)
Execute the "before sending" callbacks.
protected Response
newResponse(MessageInterface $response)
Create a new response instance using the given PSR response.
$this
stub(callable $callback)
Register a stub callable that will intercept requests and be able to return stub responses.
$this
preventStrayRequests(bool $prevent = true)
Indicate that an exception should be thrown if any request is not faked.
protected void
dispatchRequestSendingEvent()
Dispatch the RequestSending event if a dispatcher is available.
protected void
dispatchResponseReceivedEvent(Response $response)
Dispatch the ResponseReceived event if a dispatcher is available.
protected void
dispatchConnectionFailedEvent(Request $request, ConnectionException $exception)
Dispatch the ConnectionFailed event if a dispatcher is available.