Make initial server request available to middlewares

This commit is contained in:
Sebastian Meyer 2023-11-20 13:10:51 +01:00
parent 5c83208450
commit 11e9d4e827
2 changed files with 17 additions and 0 deletions

View File

@ -35,6 +35,11 @@ use Psr\Http\Server\RequestHandlerInterface;
*/
abstract class AbstractMiddleware implements MiddlewareInterface
{
/**
* The PSR-15 Server Request Handler.
*/
protected RequestHandlerInterface $handler;
/**
* The PSR-7 HTTP Server Request after processing.
*/
@ -56,6 +61,7 @@ abstract class AbstractMiddleware implements MiddlewareInterface
*/
final public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$this->handler = $handler;
// Manipulate request if necessary.
$this->request = $this->processRequest($request);
// Delegate request to next middleware and get response.

View File

@ -152,6 +152,17 @@ class QueueRequestHandler implements RequestHandlerInterface
return $this->queue;
}
/**
* Magic getter method for $this->request.
* @see Getter
*
* @return ServerRequestInterface The PSR-7 server request
*/
protected function magicGetRequest(): ServerRequestInterface
{
return $this->request;
}
/**
* Create a queue-based PSR-15 HTTP Server Request Handler.
*