DeferMiddleware
This middleware MUST be used to inject and manage a Defer instance in a PSR-15 ServerRequest.
Description
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.
Interfaces
Properties
Methods
Constructs a new DeferMiddleware instance.
Returns the attribute name used to store the Defer instance.
Retrieves the Defer instance from the request.
Processes the request, injecting the Defer instance and ensuring execution at the end.
Constructs a new DeferMiddleware instance.
public
__construct([
string
$attribute = DeferInterface::class]) : mixed
Parameters
$attribute
:
string
=
DeferInterface::class
Description
the attribute name to use for storing the Defer instance (optional)
Returns the attribute name used to store the Defer instance.
public
getAttribute() : string
Return values
Description
the attribute name
Retrieves the Defer instance from the request.
public
getDefer(ServerRequestInterface
$request) : DeferInterface
Description
This method MUST throw a LogicException if the Defer instance is not found.
Parameters
$request
:
ServerRequestInterface
Description
the request to retrieve the Defer instance from
Return values
Description
the Defer instance
Processes the request, injecting the Defer instance and ensuring execution at the end.
public
process(ServerRequestInterface
$request, RequestHandlerInterface
$handler) : ResponseInterface
Parameters
$request
:
ServerRequestInterface
Description
the incoming request
$handler
:
RequestHandlerInterface
Description
the request handler
Return values
Description
the response from the handler