Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

(no description)

File Size: 260 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Middleware:: (10 methods):
  cookies()
  httpErrors()
  history()
  tap()
  redirect()
  retry()
  log()
  prepareBody()
  mapRequest()
  mapResponse()


Class: Middleware  - X-Ref

Functions used to create and wrap handlers with handler middleware.

cookies()   X-Ref
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.

httpErrors(BodySummarizerInterface $bodySummarizer = null)   X-Ref
No description

history(&$container)   X-Ref
No description

tap(callable $before = null, callable $after = null)   X-Ref
No description

redirect()   X-Ref
Middleware that handles request redirects.

return: callable Returns a function that accepts the next handler.

retry(callable $decider, callable $delay = null)   X-Ref
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,
param: callable $delay   Function that accepts the number of retries and
return: callable Returns a function that accepts the next handler.

log(LoggerInterface $logger, $formatter, string $logLevel = 'info')   X-Ref
Middleware that logs requests, responses, and errors using a message
formatter.

param: LoggerInterface                            $logger    Logs messages.
param: MessageFormatterInterface|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.

prepareBody()   X-Ref
No description

mapRequest(callable $fn)   X-Ref
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

mapResponse(callable $fn)   X-Ref
Middleware that applies a map function to the resolved promise's
response.

param: callable $fn Function that accepts a ResponseInterface and