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 string | $baseUrl | The base URL for the request. |
|
protected string | $bodyFormat | The request body format. |
|
protected 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 | The transfer stats for the request. |
|
protected array | $options | The request options. |
|
protected int | $tries | The number of times to try the request. |
|
protected int | $retryDelay | The number of milliseconds to wait between retries. |
|
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 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 | $mergableOptions | The Guzzle request options that are mergable via array_merge_recursive. |
Methods
Apply the callback if the given "value" is truthy.
Apply the callback if the given "value" is falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
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.
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.
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 cookies that should be included with the request.
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 number of times the request should be attempted.
Replace the specified options on the request.
Add new middleware the client handler stack.
Add a new "before sending" callback to the request.
Dump the request before sending.
Dump the request before sending and end the script.
Send a pool of asynchronous requests concurrently.
Parse multi-part form data.
Send an asynchronous request to the given URL.
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.
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.
Register a stub callable that will intercept requests and be able to return stub responses.
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|mixed
when(mixed $value, callable $callback, callable|null $default = null)
Apply the callback if the given "value" is truthy.
$this|mixed
unless(mixed $value, callable $callback, callable|null $default = null)
Apply the callback if the given "value" is falsy.
static void
macro(string $name, object|callable $macro)
Register a custom macro.
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool
hasMacro(string $name)
Checks 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.
void
__construct(Factory $factory = null)
Create a new HTTP Client instance.
$this
baseUrl(string $url)
Set the base URL for the pending request.
$this
withBody(string $content, string $contentType)
Attach a raw body to the request.
$this
asJson()
Indicate the request contains JSON.
$this
asForm()
Indicate the request contains form parameters.
$this
attach(string|array $name, string|resource $contents = '', string|null $filename = null, array $headers = [])
Attach a file to the request.
$this
asMultipart()
Indicate the request is a multi-part form request.
$this
bodyFormat(string $format)
Specify the body format of the request.
$this
contentType(string $contentType)
Specify the request's content type.
$this
acceptJson()
Indicate that JSON should be returned by the server.
$this
accept(string $contentType)
Indicate the type of content that should be returned by the server.
$this
withHeaders(array $headers)
Add the given headers to the request.
$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
withUserAgent(string $userAgent)
Specify the user agent for the request.
$this
withCookies(array $cookies, string $domain)
Specify the cookies that should be included with the request.
$this
withoutRedirecting()
Indicate that redirects should not be followed.
$this
withoutVerifying()
Indicate that TLS certificates should not be verified.
$this
sink(string|resource $to)
Specify the path where the body of the response should be stored.
$this
timeout(int $seconds)
Specify the timeout (in seconds) for the request.
$this
retry(int $times, int $sleep = 0, callable|null $when = null)
Specify the number of times the request should be attempted.
$this
withOptions(array $options)
Replace the specified options on the request.
$this
withMiddleware(callable $middleware)
Add new middleware the client handler stack.
$this
beforeSending(callable $callback)
Add a new "before sending" callback to the request.
$this
dump()
Dump the request before sending.
$this
dd()
Dump the request before sending and end the script.
Response
get(string $url, array|string|null $query = null)
Issue a GET request to the given URL.
Response
head(string $url, array|string|null $query = null)
Issue a HEAD request to the given URL.
Response
post(string $url, array $data = [])
Issue a POST request to the given URL.
Response
patch(string $url, array $data = [])
Issue a PATCH request to the given URL.
Response
put(string $url, array $data = [])
Issue a PUT request to the given URL.
Response
delete(string $url, array $data = [])
Issue a DELETE request to the given URL.
array
pool(callable $callback)
Send a pool of asynchronous requests concurrently.
Response
send(string $method, string $url, array $options = [])
Send the request to the given URL.
protected array|array[]
parseMultipartBodyFormat(array $data)
Parse multi-part form data.
protected PromiseInterface
makePromise(string $method, string $url, array $options = [])
Send an asynchronous request to the given URL.
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.
Client
buildClient()
Build the Guzzle client.
protected bool
requestsReusableClient()
Determine if a reusable client is required.
protected Client
getReusableClient()
Retrieve a reusable Guzzle client.
Client
createClient(HandlerStack $handlerStack)
Create new Guzzle client.
HandlerStack
buildHandlerStack()
Build the Guzzle client handler stack.
HandlerStack
pushHandlers(HandlerStack $handlerStack)
Add the necessary handlers to the given handler stack.
Closure
buildBeforeSendingHandler()
Build the before sending handler.
Closure
buildRecorderHandler()
Build the recorder handler.
Closure
buildStubHandler()
Build the stub handler.
protected Closure
sinkStubHandler(string $sink)
Get the sink stub handler callback.
RequestInterface
runBeforeSendingCallbacks(RequestInterface $request, array $options)
Execute the "before sending" callbacks.
array
mergeOptions(array ...$options)
Replace the given options with the current request options.
$this
stub(callable $callback)
Register a stub callable that will intercept requests and be able to return stub responses.
$this
async(bool $async = true)
Toggle asynchronicity in requests.
PromiseInterface|null
getPromise()
Retrieve the pending request promise.
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()
Dispatch the ConnectionFailed event if a dispatcher is available.
$this
setClient(Client $client)
Set the client instance.
$this
setHandler(callable $handler)
Create a new client instance using the given handler.
array
getOptions()
Get the pending request options.