Copied!

Functions used to create and wrap handlers with handler middleware.

Cloneable Final Instantiable
Methods
public static cookies () : callable
 

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 callable Returns a function that accepts the next handler.
public static history ( $container ) : callable
 

Middleware that pushes history data to an ArrayAccess container.

  • param array | ArrayAccess $container Container to hold the history (by reference).
  • return
  • throws InvalidArgumentException if container is not an array or ArrayAccess.
public static httpErrors ( ? GuzzleHttp\BodySummarizerInterface $bodySummarizer = NULL ) : callable
 

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

public static log ( Psr\Log\LoggerInterface $logger , $formatter , string $logLevel = 'info' ) : callable
 

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

  • phpstan-param \Psr\Log\LogLevel::* $logLevel Level at which to log requests.
  • param LoggerInterface $logger Logs messages.
  • param GuzzleHttp\MessageFormatterInterface | GuzzleHttp\MessageFormatter $formatter Formatter used to create message strings.
  • param string $logLevel Level at which to log requests.
  • return callable Returns a function that accepts the next handler.
public static mapRequest ( callable $fn ) : callable
 

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

  • param callable $fn Function that accepts a RequestInterface and returns
    a RequestInterface.
public static mapResponse ( callable $fn ) : callable
 

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

  • param callable $fn Function that accepts a ResponseInterface and
    returns a ResponseInterface.
public static prepareBody () : callable
 

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

public static redirect () : callable
 

Middleware that handles request redirects.

  • return callable Returns a function that accepts the next handler.
public static retry ( callable $decider , ? callable $delay = NULL ) : callable
 

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.

  • param callable $decider Function that accepts the number of retries,
    a request, [response], and [exception] and
    returns true if the request is to be retried.
  • param callable $delay Function that accepts the number of retries and
    returns the number of milliseconds to delay.
  • return callable Returns a function that accepts the next handler.
public static tap ( ? callable $before = NULL , ? callable $after = NULL ) : callable
 

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.

  • param callable $before Function to invoke before forwarding the request.
  • param callable $after Function invoked after forwarding.
  • return callable Returns a function that accepts the next handler.
Methods
public static cookies () : callable
 

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 callable Returns a function that accepts the next handler.
public static history ( $container ) : callable
 

Middleware that pushes history data to an ArrayAccess container.

  • param array | ArrayAccess $container Container to hold the history (by reference).
  • return
  • throws InvalidArgumentException if container is not an array or ArrayAccess.
public static httpErrors ( ? GuzzleHttp\BodySummarizerInterface $bodySummarizer = NULL ) : callable
 

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

public static log ( Psr\Log\LoggerInterface $logger , $formatter , string $logLevel = 'info' ) : callable
 

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

  • phpstan-param \Psr\Log\LogLevel::* $logLevel Level at which to log requests.
  • param LoggerInterface $logger Logs messages.
  • param GuzzleHttp\MessageFormatterInterface | GuzzleHttp\MessageFormatter $formatter Formatter used to create message strings.
  • param string $logLevel Level at which to log requests.
  • return callable Returns a function that accepts the next handler.
public static mapRequest ( callable $fn ) : callable
 

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

  • param callable $fn Function that accepts a RequestInterface and returns
    a RequestInterface.
public static mapResponse ( callable $fn ) : callable
 

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

  • param callable $fn Function that accepts a ResponseInterface and
    returns a ResponseInterface.
public static prepareBody () : callable
 

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

public static redirect () : callable
 

Middleware that handles request redirects.

  • return callable Returns a function that accepts the next handler.
public static retry ( callable $decider , ? callable $delay = NULL ) : callable
 

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.

  • param callable $decider Function that accepts the number of retries,
    a request, [response], and [exception] and
    returns true if the request is to be retried.
  • param callable $delay Function that accepts the number of retries and
    returns the number of milliseconds to delay.
  • return callable Returns a function that accepts the next handler.
public static tap ( ? callable $before = NULL , ? callable $after = NULL ) : callable
 

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.

  • param callable $before Function to invoke before forwarding the request.
  • param callable $after Function invoked after forwarding.
  • return callable Returns a function that accepts the next handler.
© 2022 Bruce Wells
Search Namespaces \ Classes
Configuration