diff --git a/.gitignore b/.gitignore index 101fb37..a9783a8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /composer.lock vendor/ local-php-security-checker +/.idea \ No newline at end of file diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index d1148ed..e19d61a 100644 --- a/src/Controller/ApiController.php +++ b/src/Controller/ApiController.php @@ -99,7 +99,7 @@ public function handle(Request $request): Response $this->eventDispatcher->dispatch(new ResponseDtoEvent($responseDto, $operationId, $specification)); $response = $this->createResponse($requestHandler, $operation, $requestHandlerInterface, $responseDto); - $this->eventDispatcher->dispatch(new ResponseEvent($response, $operationId, $specification)); + $this->eventDispatcher->dispatch(new ResponseEvent($response, $operationId, $specification, $requestHandler, $request)); return $response; } diff --git a/src/Event/Server/ResponseEvent.php b/src/Event/Server/ResponseEvent.php index a2fa760..3474955 100644 --- a/src/Event/Server/ResponseEvent.php +++ b/src/Event/Server/ResponseEvent.php @@ -4,7 +4,9 @@ namespace OnMoon\OpenApiServerBundle\Event\Server; +use OnMoon\OpenApiServerBundle\Interfaces\RequestHandler; use OnMoon\OpenApiServerBundle\Specification\Definitions\Specification; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\EventDispatcher\Event; @@ -20,12 +22,16 @@ final class ResponseEvent extends Event private Response $response; private string $operationId; private Specification $specification; + private RequestHandler $requestHandler; + private Request $request; - public function __construct(Response $response, string $operationId, Specification $specification) + public function __construct(Response $response, string $operationId, Specification $specification, RequestHandler $requestHandler, Request $request) { - $this->response = $response; - $this->operationId = $operationId; - $this->specification = $specification; + $this->response = $response; + $this->operationId = $operationId; + $this->specification = $specification; + $this->requestHandler = $requestHandler; + $this->request = $request; } public function getResponse(): Response @@ -42,4 +48,14 @@ public function getSpecification(): Specification { return $this->specification; } + + public function getRequestHandler(): RequestHandler + { + return $this->requestHandler; + } + + public function getRequest(): Request + { + return $this->request; + } } diff --git a/test/unit/Event/Server/ResponseEventTest.php b/test/unit/Event/Server/ResponseEventTest.php index d1d487f..465d77c 100644 --- a/test/unit/Event/Server/ResponseEventTest.php +++ b/test/unit/Event/Server/ResponseEventTest.php @@ -6,9 +6,11 @@ use cebe\openapi\spec\OpenApi; use OnMoon\OpenApiServerBundle\Event\Server\ResponseEvent; +use OnMoon\OpenApiServerBundle\Interfaces\RequestHandler; use OnMoon\OpenApiServerBundle\Specification\Definitions\Specification; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; /** @@ -18,14 +20,19 @@ final class ResponseEventTest extends TestCase { public function testResponseEventGettersReturnCorrectValues(): void { - $response = new Response(); - $operationId = '12345'; - $specification = new Specification([], [], new OpenApi([])); + $response = new Response(); + $operationId = '12345'; + $specification = new Specification([], [], new OpenApi([])); + $requestHandler = new class () implements RequestHandler{ + }; + $request = new Request(); - $responseEvent = new ResponseEvent($response, $operationId, $specification); + $responseEvent = new ResponseEvent($response, $operationId, $specification, $requestHandler, $request); Assert::assertEquals($response, $responseEvent->getResponse()); Assert::assertEquals($operationId, $responseEvent->getOperationId()); Assert::assertEquals($specification, $responseEvent->getSpecification()); + Assert::assertEquals($requestHandler, $responseEvent->getRequestHandler()); + Assert::assertEquals($request, $responseEvent->getRequest()); } }