PendingRequest
Uses
Properties
$client GuzzleHttp\Client
The Guzzle client instance.
$baseUrl string
The base URL for the request.
$bodyFormat string
The request body format.
$pendingBody string
The raw body for the request.
$pendingFiles array
The pending files for the request.
$cookies array
The request cookies.
$transferStats
The transfer stats for the request.
\GuzzleHttp\TransferStats
$options array
The request options.
$tries int
The number of times to try the request.
$retryDelay int
The number of milliseconds to wait between retries.
$retryWhenCallback callable|null
The callback that will determine if the request should be retried.
$beforeSendingCallbacks Collection
The callbacks that should execute before the request is sent.
$stubCallbacks Collection |null
The stub callables that will handle requests.
$middleware Collection
The middleware callables added by users that will handle requests.
$async bool
Whether the requests should be asynchronous.
$promise GuzzleHttp\...\PromiseInterface
The pending request promise.
$mergableOptions array
The Guzzle request options that are mergable via array_merge_recursive.
Methods
__construct ( Factory $factory ) : void
Create a new HTTP Client instance.
Parameters
- $factory Factory |null
baseUrl ( string $url ) : $this
Set the base URL for the pending request.
Parameters
- $url string
withBody ( $content , $contentType ) : $this
Attach a raw body to the request.
Parameters
- $content string
- $contentType string
asJson ( ) : $this
Indicate the request contains JSON.
asForm ( ) : $this
Indicate the request contains form parameters.
attach ( $name , $contents , $filename , array $headers ) : $this
Attach a file to the request.
Parameters
- $name string|array
- $contents string|resource
- $filename string|null
- $headers array
asMultipart ( ) : $this
Indicate the request is a multi-part form request.
bodyFormat ( string $format ) : $this
Specify the body format of the request.
Parameters
- $format string
contentType ( string $contentType ) : $this
Specify the request's content type.
Parameters
- $contentType string
acceptJson ( ) : $this
Indicate that JSON should be returned by the server.
accept ( $contentType ) : $this
Indicate the type of content that should be returned by the server.
Parameters
- $contentType string
withHeaders ( array $headers ) : $this
Add the given headers to the request.
Parameters
- $headers array
withBasicAuth ( string $username , string $password ) : $this
Specify the basic authentication username and password for the request.
Parameters
- $username string
- $password string
withDigestAuth ( $username , $password ) : $this
Specify the digest authentication username and password for the request.
Parameters
- $username string
- $password string
withToken ( $token , $type ) : $this
Specify an authorization token for the request.
Parameters
- $token string
- $type string
withUserAgent ( $userAgent ) : $this
Specify the user agent for the request.
Parameters
- $userAgent string
withCookies ( array $cookies , string $domain ) : $this
Specify the cookies that should be included with the request.
Parameters
- $cookies array
- $domain string
withoutRedirecting ( ) : $this
Indicate that redirects should not be followed.
withoutVerifying ( ) : $this
Indicate that TLS certificates should not be verified.
sink ( $to ) : $this
Specify the path where the body of the response should be stored.
Parameters
- $to string|resource
timeout ( int $seconds ) : $this
Specify the timeout (in seconds) for the request.
Parameters
- $seconds int
retry ( int $times , int $sleep , callable $when ) : $this
Specify the number of times the request should be attempted.
Parameters
- $times int
- $sleep int
- $when callable|null
withOptions ( array $options ) : $this
Replace the specified options on the request.
Parameters
- $options array
withMiddleware ( callable $middleware ) : $this
Add new middleware the client handler stack.
Parameters
- $middleware callable
beforeSending ( $callback ) : $this
Add a new "before sending" callback to the request.
Parameters
- $callback callable
dump ( ) : $this
Dump the request before sending.
dd ( ) : $this
Dump the request before sending and end the script.
get ( string $url , $query ) : Response
Issue a GET request to the given URL.
Parameters
- $url string
- $query array|string|null
head ( string $url , $query ) : Response
Issue a HEAD request to the given URL.
Parameters
- $url string
- $query array|string|null
post ( string $url , array $data ) : Response
Issue a POST request to the given URL.
Parameters
- $url string
- $data array
patch ( $url , $data ) : Response
Issue a PATCH request to the given URL.
Parameters
- $url string
- $data array
put ( $url , $data ) : Response
Issue a PUT request to the given URL.
Parameters
- $url string
- $data array
delete ( $url , $data ) : Response
Issue a DELETE request to the given URL.
Parameters
- $url string
- $data array
pool ( callable $callback ) : array
Send a pool of asynchronous requests concurrently.
Parameters
- $callback callable
send ( string $method , string $url , array $options ) : Response
Send the request to the given URL.
Parameters
- $method string
- $url string
- $options array
parseMultipartBodyFormat ( array $data ) : array|array[]
Parse multi-part form data.
Parameters
- $data array
makePromise ( string $method , string $url , array $options ) : GuzzleHttp\...\PromiseInterface
Send an asynchronous request to the given URL.
Parameters
- $method string
- $url string
- $options array
sendRequest ( string $method , string $url , array $options ) : Psr\...\MessageInterface|GuzzleHttp\...\PromiseInterface
Send a request either synchronously or asynchronously.
Parameters
- $method string
- $url string
- $options array
parseRequestData ( $method , $url , array $options ) : array
Get the request data as an array so that we can attach it to the request for convenient assertions.
Parameters
- $method string
- $url string
- $options array
populateResponse ( Response $response ) : Response
Populate the given response with additional data.
Parameters
- $response Response
buildClient ( ) : GuzzleHttp\Client
Build the Guzzle client.
requestsReusableClient ( ) : bool
Determine if a reusable client is required.
getReusableClient ( ) : GuzzleHttp\Client
Retrieve a reusable Guzzle client.
createClient ( $handlerStack ) : GuzzleHttp\Client
Create new Guzzle client.
Parameters
- $handlerStack GuzzleHttp\HandlerStack
buildHandlerStack ( ) : GuzzleHttp\HandlerStack
Build the Guzzle client handler stack.
pushHandlers ( $handlerStack ) : GuzzleHttp\HandlerStack
Add the necessary handlers to the given handler stack.
Parameters
- $handlerStack GuzzleHttp\HandlerStack
sinkStubHandler ( $sink ) : Closure
Get the sink stub handler callback.
Parameters
- $sink string
runBeforeSendingCallbacks ( $request , array $options ) : GuzzleHttp\...\RequestInterface
Execute the "before sending" callbacks.
Parameters
- $request GuzzleHttp\...\RequestInterface
- $options array
mergeOptions ( $options ) : array
Replace the given options with the current request options.
Parameters
- $options array
stub ( $callback ) : $this
Register a stub callable that will intercept requests and be able to return stub responses.
Parameters
- $callback callable
async ( bool $async ) : $this
Toggle asynchronicity in requests.
Parameters
- $async bool
getPromise ( ) : GuzzleHttp\...\PromiseInterface|null
Retrieve the pending request promise.
dispatchRequestSendingEvent ( ) : void
Dispatch the RequestSending event if a dispatcher is available.
dispatchResponseReceivedEvent ( Response $response ) : void
Dispatch the ResponseReceived event if a dispatcher is available.
Parameters
- $response Response
dispatchConnectionFailedEvent ( ) : void
Dispatch the ConnectionFailed event if a dispatcher is available.
setClient ( GuzzleHttp\Client $client ) : $this
Set the client instance.
Parameters
- $client GuzzleHttp\Client
setHandler ( $handler ) : $this
Create a new client instance using the given handler.
Parameters
- $handler callable
getOptions ( ) : array
Get the pending request options.