class Illuminate / Http / Client / PendingRequest
You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.

PendingRequest

Uses

Properties

protected

$factory Factory |null

The factory instance.

Default: null
protected

$client GuzzleHttp\Client

The Guzzle client instance.

Default: null
protected

$handler callable

The Guzzle HTTP handler.

Default: null
protected

$baseUrl string

The base URL for the request.

Default: ''
protected

$urlParameters array

The parameters that can be substituted into the URL.

Default: []
protected

$bodyFormat string

The request body format.

Default: null
protected

$pendingBody string

The raw body for the request.

Default: null
protected

$pendingFiles array

The pending files for the request.

Default: []
protected

$cookies array

The request cookies.

Default: null
protected

$transferStats GuzzleHttp\TransferStats

The transfer stats for the request.

Default: null
protected

$options array

The request options.

Default: []
protected

$throwCallback Closure

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

Default: null
protected

$throwIfCallback Closure

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

Default: null
protected

$tries int

The number of times to try the request.

Default: 1
protected

$retryDelay Closure |int

The number of milliseconds to wait between retries.

Default: 100
protected

$retryThrow bool

Whether to throw an exception when all retries fail.

Default: true
protected

$retryWhenCallback callable|null

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

Default: null
protected

$beforeSendingCallbacks Illuminate\...\Collection

The callbacks that should execute before the request is sent.

Default: null
protected

$stubCallbacks Illuminate\...\Collection|null

The stub callables that will handle requests.

Default: null
protected

$preventStrayRequests bool

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

Default: false
protected

$middleware Illuminate\...\Collection

The middleware callables added by users that will handle requests.

Default: null
protected

$async bool

Whether the requests should be asynchronous.

Default: false
protected

$promise GuzzleHttp\...\PromiseInterface

The pending request promise.

Default: null
protected

$request Request |null

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

Default: null
protected

$mergableOptions array

The Guzzle request options that are mergable via array_merge_recursive.

Default: array

Methods

public

__construct ( Factory $factory , $middleware ) : void

Create a new HTTP Client instance.

Parameters

  • $factory Factory |null
  • $middleware array
public

baseUrl ( string $url ) : $this

Set the base URL for the pending request.

Parameters

  • $url string
public

withBody ( $content , $contentType ) : $this

Attach a raw body to the request.

Parameters

  • $content string
  • $contentType string
public

asJson ( ) : $this

Indicate the request contains JSON.

public

asForm ( ) : $this

Indicate the request contains form parameters.

public

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
public

asMultipart ( ) : $this

Indicate the request is a multi-part form request.

public

bodyFormat ( string $format ) : $this

Specify the body format of the request.

Parameters

  • $format string
public

withQueryParameters ( array $parameters ) : $this

Set the given query parameters in the request URI.

Parameters

  • $parameters array
public

contentType ( string $contentType ) : $this

Specify the request's content type.

Parameters

  • $contentType string
public

acceptJson ( ) : $this

Indicate that JSON should be returned by the server.

public

accept ( $contentType ) : $this

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

Parameters

  • $contentType string
public

withHeaders ( array $headers ) : $this

Add the given headers to the request.

Parameters

  • $headers array
public

withHeader ( $name , $value ) : $this

Add the given header to the request.

Parameters

  • $name string
  • $value mixed
public

replaceHeaders ( array $headers ) : $this

Replace the given headers on the request.

Parameters

  • $headers array
public

withBasicAuth ( string $username , string $password ) : $this

Specify the basic authentication username and password for the request.

Parameters

  • $username string
  • $password string
public

withDigestAuth ( $username , $password ) : $this

Specify the digest authentication username and password for the request.

Parameters

  • $username string
  • $password string
public

withToken ( $token , $type ) : $this

Specify an authorization token for the request.

Parameters

  • $token string
  • $type string
public

withUserAgent ( $userAgent ) : $this

Specify the user agent for the request.

Parameters

  • $userAgent string|bool
public

withUrlParameters ( array $parameters ) : $this

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

Parameters

  • $parameters array
public

withCookies ( array $cookies , string $domain ) : $this

Specify the cookies that should be included with the request.

Parameters

  • $cookies array
  • $domain string
public

maxRedirects ( int $max ) : $this

Specify the maximum number of redirects to allow.

Parameters

  • $max int
public

withoutRedirecting ( ) : $this

Indicate that redirects should not be followed.

public

withoutVerifying ( ) : $this

Indicate that TLS certificates should not be verified.

public

sink ( $to ) : $this

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

Parameters

  • $to string|resource
public

timeout ( int $seconds ) : $this

Specify the timeout (in seconds) for the request.

Parameters

  • $seconds int
public

connectTimeout ( int $seconds ) : $this

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

Parameters

  • $seconds int
public

retry ( int $times , $sleepMilliseconds , callable $when , bool $throw ) : $this

Specify the number of times the request should be attempted.

Parameters

  • $times int
  • $sleepMilliseconds Closure |int
  • $when callable|null
  • $throw bool
public

withOptions ( array $options ) : $this

Replace the specified options on the request.

Parameters

  • $options array
public

withMiddleware ( callable $middleware ) : $this

Add new middleware the client handler stack.

Parameters

  • $middleware callable
public

withRequestMiddleware ( callable $middleware ) : $this

Add new request middleware the client handler stack.

Parameters

  • $middleware callable
public

withResponseMiddleware ( callable $middleware ) : $this

Add new response middleware the client handler stack.

Parameters

  • $middleware callable
public

beforeSending ( $callback ) : $this

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

Parameters

  • $callback callable
public

throw ( callable $callback ) : $this

Throw an exception if a server or client error occurs.

Parameters

  • $callback callable|null
public

throwIf ( $condition ) : $this

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

Parameters

  • $condition callable|bool
  • $throwCallback callable|null
public

throwUnless ( $condition ) : $this

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

Parameters

  • $condition bool
public

dump ( ) : $this

Dump the request before sending.

public

dd ( ) : $this

Dump the request before sending and end the script.

public

get ( string $url , $query ) : Response

Issue a GET request to the given URL.

Parameters

  • $url string
  • $query array|string|null
public

Issue a HEAD request to the given URL.

Parameters

  • $url string
  • $query array|string|null
public

post ( string $url , $data ) : Response

Issue a POST request to the given URL.

Parameters

  • $url string
  • $data array
public

patch ( string $url , $data ) : Response

Issue a PATCH request to the given URL.

Parameters

  • $url string
  • $data array
public

put ( string $url , $data ) : Response

Issue a PUT request to the given URL.

Parameters

  • $url string
  • $data array
public

delete ( string $url , $data ) : Response

Issue a DELETE request to the given URL.

Parameters

  • $url string
  • $data array
public

pool ( callable $callback ) : array

Send a pool of asynchronous requests concurrently.

Parameters

  • $callback callable
public

send ( string $method , string $url , array $options ) : Response

Send the request to the given URL.

Parameters

  • $method string
  • $url string
  • $options array
protected

expandUrlParameters ( string $url ) : string

Substitute the URL parameters in the given URL.

Parameters

  • $url string
protected

parseHttpOptions ( array $options ) : array

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

Parameters

  • $options array
protected

parseMultipartBodyFormat ( array $data ) : array|array[]

Parse multi-part form data.

Parameters

  • $data array
protected

makePromise ( string $method , string $url , array $options ) : GuzzleHttp\...\PromiseInterface

Send an asynchronous request to the given URL.

Parameters

  • $method string
  • $url string
  • $options array
protected

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
protected

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
protected

populateResponse ( Response $response ) : Response

Populate the given response with additional data.

Parameters

public

buildClient ( ) : GuzzleHttp\Client

Build the Guzzle client.

protected

requestsReusableClient ( ) : bool

Determine if a reusable client is required.

protected

getReusableClient ( ) : GuzzleHttp\Client

Retrieve a reusable Guzzle client.

public

createClient ( $handlerStack ) : GuzzleHttp\Client

Create new Guzzle client.

Parameters

  • $handlerStack GuzzleHttp\HandlerStack
public

buildHandlerStack ( ) : GuzzleHttp\HandlerStack

Build the Guzzle client handler stack.

public

pushHandlers ( $handlerStack ) : GuzzleHttp\HandlerStack

Add the necessary handlers to the given handler stack.

Parameters

  • $handlerStack GuzzleHttp\HandlerStack
public

buildBeforeSendingHandler ( ) : Closure

Build the before sending handler.

public

buildRecorderHandler ( ) : Closure

Build the recorder handler.

public

buildStubHandler ( ) : Closure

Build the stub handler.

protected

sinkStubHandler ( $sink ) : Closure

Get the sink stub handler callback.

Parameters

  • $sink string
public

runBeforeSendingCallbacks ( $request , array $options ) : GuzzleHttp\...\RequestInterface

Execute the "before sending" callbacks.

Parameters

  • $request GuzzleHttp\...\RequestInterface
  • $options array
public

mergeOptions ( $options ) : array

Replace the given options with the current request options.

Parameters

  • $options array
public

stub ( $callback ) : $this

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

Parameters

  • $callback callable
public

preventStrayRequests ( $prevent ) : $this

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

Parameters

  • $prevent bool
public

async ( bool $async ) : $this

Toggle asynchronicity in requests.

Parameters

  • $async bool
public

getPromise ( ) : GuzzleHttp\...\PromiseInterface|null

Retrieve the pending request promise.

protected

dispatchRequestSendingEvent ( ) : void

Dispatch the RequestSending event if a dispatcher is available.

protected

dispatchResponseReceivedEvent ( Response $response ) : void

Dispatch the ResponseReceived event if a dispatcher is available.

Parameters

protected

dispatchConnectionFailedEvent ( ) : void

Dispatch the ConnectionFailed event if a dispatcher is available.

public

setClient ( GuzzleHttp\Client $client ) : $this

Set the client instance.

Parameters

  • $client GuzzleHttp\Client
public

setHandler ( $handler ) : $this

Create a new client instance using the given handler.

Parameters

  • $handler callable
public

getOptions ( ) : array

Get the pending request options.