Middleware API
DeferMiddleware
FastForward\Defer\Middleware\DeferMiddleware
implements
Psr\Http\Server\MiddlewareInterface
and provides request-scoped cleanup.
Constructor
public function __construct(string $attribute = DeferInterface::class)
The constructor controls the request attribute name used to store the scope.
Public methods
getAttribute(): string- Returns the configured request attribute name.
getDefer(ServerRequestInterface $request): DeferInterface- Reads the configured attribute and validates that it contains a
DeferInterfaceimplementation. ThrowsLogicExceptionotherwise. process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface- Creates a new
Deferinstance, injects it into the request, calls the next handler, and unsets the scope in afinallyblock.
Behavior summary
- One middleware invocation creates one new
Deferscope. - The scope is request-local.
- Cleanup runs whether the handler returns normally or throws.