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: 275 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

HandlerStack:: (15 methods):
  create()
  __construct()
  __invoke()
  __toString()
  setHandler()
  hasHandler()
  unshift()
  push()
  before()
  after()
  remove()
  resolve()
  findByName()
  splice()
  debugCallable()


Class: HandlerStack  - X-Ref

Creates a composed Guzzle handler function by stacking middlewares on top of
an HTTP handler function.

create(?callable $handler = null)   X-Ref
Creates a default handler stack that can be used by clients.

The returned handler will wrap the provided handler or use the most
appropriate default handler for your system. The returned HandlerStack has
support for cookies, redirects, HTTP error exceptions, and preparing a body
before sending.

The returned handler stack can be passed to a client in the "handler"
option.

param: (callable(RequestInterface, array): PromiseInterface)|null $handler HTTP handler function to use with the stack. If no

__construct(callable $handler = null)   X-Ref

param: (callable(RequestInterface, array): PromiseInterface)|null $handler Underlying HTTP handler.

__invoke(RequestInterface $request, array $options)   X-Ref
Invokes the handler stack as a composed handler

return: ResponseInterface|PromiseInterface

__toString()   X-Ref
Dumps a string representation of the stack.

return: string

setHandler(callable $handler)   X-Ref
Set the HTTP handler that actually returns a promise.

param: callable(RequestInterface, array): PromiseInterface $handler Accepts a request and array of options and

hasHandler()   X-Ref
Returns true if the builder has a handler.


unshift(callable $middleware, ?string $name = null)   X-Ref
Unshift a middleware to the bottom of the stack.

param: callable(callable): callable $middleware Middleware function
param: string                       $name       Name to register for this middleware.

push(callable $middleware, string $name = '')   X-Ref
Push a middleware to the top of the stack.

param: callable(callable): callable $middleware Middleware function
param: string                       $name       Name to register for this middleware.

before(string $findName, callable $middleware, string $withName = '')   X-Ref
Add a middleware before another middleware by name.

param: string                       $findName   Middleware to find
param: callable(callable): callable $middleware Middleware function
param: string                       $withName   Name to register for this middleware.

after(string $findName, callable $middleware, string $withName = '')   X-Ref
Add a middleware after another middleware by name.

param: string                       $findName   Middleware to find
param: callable(callable): callable $middleware Middleware function
param: string                       $withName   Name to register for this middleware.

remove($remove)   X-Ref
Remove a middleware by instance or name from the stack.

param: callable|string $remove Middleware to remove by instance or name.

resolve()   X-Ref
No description

findByName(string $name)   X-Ref
No description

splice(string $findName, string $withName, callable $middleware, bool $before)   X-Ref
Splices a function into the middleware list at a specific position.


debugCallable($fn)   X-Ref
Provides a debug string for a given callable.

param: callable|string $fn Function to write as a string.