From 11e9d4e8279762ffcc9cc0fed64456213475b5c2 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Mon, 20 Nov 2023 13:10:51 +0100 Subject: [PATCH] Make initial server request available to middlewares --- src/AbstractMiddleware.php | 6 ++++++ src/QueueRequestHandler.php | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/AbstractMiddleware.php b/src/AbstractMiddleware.php index d22f64d..dbf0085 100644 --- a/src/AbstractMiddleware.php +++ b/src/AbstractMiddleware.php @@ -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. diff --git a/src/QueueRequestHandler.php b/src/QueueRequestHandler.php index cb8472d..8c2a19d 100644 --- a/src/QueueRequestHandler.php +++ b/src/QueueRequestHandler.php @@ -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. *