Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
GuzzleHttp\Middleware Class Reference

Static Public Member Functions

static cookies ()
 Middleware that adds cookies to requests.
 
static history (&$container)
 Middleware that pushes history data to an ArrayAccess container.
 
static httpErrors (BodySummarizerInterface $bodySummarizer=null)
 Middleware that throws exceptions for 4xx or 5xx responses when the "http_errors" request option is set to true.
 
static log (LoggerInterface $logger, $formatter, string $logLevel='info')
 Middleware that logs requests, responses, and errors using a message formatter.
 
static mapRequest (callable $fn)
 Middleware that applies a map function to the request before passing to the next handler.
 
static mapResponse (callable $fn)
 Middleware that applies a map function to the resolved promise's response.
 
static prepareBody ()
 This middleware adds a default content-type if possible, a default content-length or transfer-encoding header, and the expect header.
 
static redirect ()
 Middleware that handles request redirects.
 
static retry (callable $decider, callable $delay=null)
 Middleware that retries requests based on the boolean result of invoking the provided "decider" function.
 
static tap (callable $before=null, callable $after=null)
 Middleware that invokes a callback before and after sending a request.
 

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.

Return values
callableReturns a function that accepts the next handler.

◆ history()

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

Middleware that pushes history data to an ArrayAccess container.

Parameters
array|ArrayAccess<int,array>$container Container to hold the history (by reference).
Return values
callable(callable)callable Returns a function that accepts the next handler.
Exceptions
InvalidArgumentExceptionif container is not an array or ArrayAccess.

◆ httpErrors()

static GuzzleHttp\Middleware::httpErrors ( BodySummarizerInterface $bodySummarizer = null)
static

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

Parameters
BodySummarizerInterface | null$bodySummarizerThe body summarizer to use in exception messages.
Return values
callable(callable)callable Returns a function that accepts the next handler.

◆ log()

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

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

@phpstan-param Psr\Log\LogLevel::* $logLevel Level at which to log requests.

Parameters
LoggerInterface$loggerLogs messages.
MessageFormatterInterface | MessageFormatter$formatterFormatter used to create message strings.
string$logLevelLevel at which to log requests.
Return values
callableReturns a function that accepts the next handler.

◆ 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.

◆ 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.

◆ redirect()

static GuzzleHttp\Middleware::redirect ( )
static

Middleware that handles request redirects.

Return values
callableReturns a function that accepts the next handler.

◆ 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.
Return values
callableReturns a function that accepts the next handler.

◆ 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.
Return values
callableReturns a function that accepts the next handler.

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