Open Journal Systems  3.3.0
GuzzleHttp\Middleware Class Reference

Static Public Member Functions

static cookies ()
 
static history (&$container)
 
static httpErrors ()
 
static log (LoggerInterface $logger, MessageFormatter $formatter, $logLevel='info')
 
static mapRequest (callable $fn)
 
static mapResponse (callable $fn)
 
static prepareBody ()
 
static redirect ()
 
static retry (callable $decider, callable $delay=null)
 
static tap (callable $before=null, callable $after=null)
 

Detailed Description

Functions used to create and wrap handlers with handler middleware.

Definition at line 14 of file Middleware.php.

Member Function Documentation

◆ cookies()

static GuzzleHttp\Middleware::cookies ( )
static

Middleware that adds cookies to requests.

The options array must be set to a CookieJarInterface in order to use cookies. This is typically handled for you by a client.

Returns
callable Returns a function that accepts the next handler.

Definition at line 24 of file Middleware.php.

◆ history()

static GuzzleHttp\Middleware::history ( $container)
static

Middleware that pushes history data to an ArrayAccess container.

Parameters
array | \ArrayAccess$containerContainer to hold the history (by reference).
Returns
callable Returns a function that accepts the next handler.
Exceptions

Definition at line 80 of file Middleware.php.

◆ httpErrors()

static GuzzleHttp\Middleware::httpErrors ( )
static

Middleware that throws exceptions for 4xx or 5xx responses when the "http_error" request option is set to true.

Returns
callable Returns a function that accepts the next handler.

Definition at line 52 of file Middleware.php.

◆ log()

static GuzzleHttp\Middleware::log ( LoggerInterface  $logger,
MessageFormatter  $formatter,
  $logLevel = 'info' 
)
static

Middleware that logs requests, responses, and errors using a message formatter.

Parameters
LoggerInterface$loggerLogs messages.
MessageFormatter$formatterFormatter used to create message strings.
string$logLevelLevel at which to log requests.
Returns
callable Returns a function that accepts the next handler.

Definition at line 185 of file Middleware.php.

References GuzzleHttp\MessageFormatter\format(), and GuzzleHttp\Exception\RequestException\getResponse().

◆ mapRequest()

static GuzzleHttp\Middleware::mapRequest ( callable  $fn)
static

Middleware that applies a map function to the request before passing to the next handler.

Parameters
callable$fnFunction that accepts a RequestInterface and returns a RequestInterface.
Returns
callable

Definition at line 229 of file Middleware.php.

◆ mapResponse()

static GuzzleHttp\Middleware::mapResponse ( callable  $fn)
static

Middleware that applies a map function to the resolved promise's response.

Parameters
callable$fnFunction that accepts a ResponseInterface and returns a ResponseInterface.
Returns
callable

Definition at line 246 of file Middleware.php.

◆ prepareBody()

static GuzzleHttp\Middleware::prepareBody ( )
static

This middleware adds a default content-type if possible, a default content-length or transfer-encoding header, and the expect header.

Returns
callable

Definition at line 214 of file Middleware.php.

◆ redirect()

static GuzzleHttp\Middleware::redirect ( )
static

Middleware that handles request redirects.

Returns
callable Returns a function that accepts the next handler.

Definition at line 146 of file Middleware.php.

◆ retry()

static GuzzleHttp\Middleware::retry ( callable  $decider,
callable  $delay = null 
)
static

Middleware that retries requests based on the boolean result of invoking the provided "decider" function.

If no delay function is provided, a simple implementation of exponential backoff will be utilized.

Parameters
callable$deciderFunction that accepts the number of retries, a request, [response], and [exception] and returns true if the request is to be retried.
callable$delayFunction that accepts the number of retries and returns the number of milliseconds to delay.
Returns
callable Returns a function that accepts the next handler.

Definition at line 168 of file Middleware.php.

◆ tap()

static GuzzleHttp\Middleware::tap ( callable  $before = null,
callable  $after = null 
)
static

Middleware that invokes a callback before and after sending a request.

The provided listener cannot modify or alter the response. It simply "taps" into the chain to be notified before returning the promise. The before listener accepts a request and options array, and the after listener accepts a request, options array, and response promise.

Parameters
callable$beforeFunction to invoke before forwarding the request.
callable$afterFunction invoked after forwarding.
Returns
callable Returns a function that accepts the next handler.

Definition at line 125 of file Middleware.php.


The documentation for this class was generated from the following file: