DeferMiddleware

Class
implements MiddlewareInterface
Read only: Yes Final: Yes

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.

Table of Contents

Interfaces

Properties

 : string

Methods

__construct()

Constructs a new DeferMiddleware instance.

 : mixed
getAttribute()

Returns the attribute name used to store the Defer instance.

 : string
getDefer()

Retrieves the Defer instance from the request.

 : DeferInterface
process()

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

 : ResponseInterface
Properties

$attribute

Private
private string $attribute = DeferInterface::class
Methods

__construct()

Public

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)

getAttribute()

Public

Returns the attribute name used to store the Defer instance.

public getAttribute() : string
Return values
string

Description

the attribute name

getDefer()

Public

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

Tags
throws
LogicException
Return values

Description

the Defer instance

process()

Public

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
ResponseInterface

Description

the response from the handler