Skip to content

DeferMiddleware

github-actions edited this page Mar 26, 2026 · 1 revision

This middleware MUST be used to inject and manage a Defer instance in a PSR-15 ServerRequest.

It SHALL ensure that all deferred callbacks are executed at the end of the request lifecycle. The attribute name MAY be customized via the constructor.


  • Full name: \FastForward\Defer\Middleware\DeferMiddleware
  • This class is marked as final and can't be subclassed
  • This class implements: MiddlewareInterface
  • This class is a Final class

Methods

__construct

Constructs a new DeferMiddleware instance.

public __construct(string $attribute = \FastForward\Defer\DeferInterface::class): mixed

Parameters:

Parameter Type Description
$attribute string the attribute name to use for storing the Defer instance (optional)

getAttribute

Returns the attribute name used to store the Defer instance.

public getAttribute(): string

Return Value:

the attribute name


getDefer

Retrieves the Defer instance from the request.

public getDefer(\Psr\Http\Message\ServerRequestInterface $request): \FastForward\Defer\DeferInterface

This method MUST throw a LogicException if the Defer instance is not found.

Parameters:

Parameter Type Description
$request \Psr\Http\Message\ServerRequestInterface the request to retrieve the Defer instance from

Return Value:

the Defer instance

Throws:


process

Processes the request, injecting the Defer instance and ensuring execution at the end.

public process(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface

Parameters:

Parameter Type Description
$request \Psr\Http\Message\ServerRequestInterface the incoming request
$handler \Psr\Http\Server\RequestHandlerInterface the request handler

Return Value:

the response from the handler


Clone this wiki locally