diff --git a/composer.json b/composer.json index 72adfc10..666dad75 100644 --- a/composer.json +++ b/composer.json @@ -66,6 +66,7 @@ "preferred-install": { "*": "dist" }, + "process-timeout": 14400, "sort-packages": true, "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, diff --git a/src/CodeGenerator/NameGenerator.php b/src/CodeGenerator/NameGenerator.php index 5072050b..2f3681f2 100644 --- a/src/CodeGenerator/NameGenerator.php +++ b/src/CodeGenerator/NameGenerator.php @@ -126,7 +126,7 @@ public function setRequestNames(RequestDtoDefinition $request, string $operation public function setResponseNames(ResponseDtoDefinition $response, string $responseNamespace, string $operationName, string $responsePath): void { try { - $statusNamespace = $this->httpstatus->getReasonPhrase($response->getStatusCode()); + $statusNamespace = $this->httpstatus->getReasonPhrase((int) $response->getStatusCode()); } catch (Throwable $e) { $statusNamespace = $response->getStatusCode(); } diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index 3cbeb4d7..771ca8e4 100644 --- a/src/Controller/ApiController.php +++ b/src/Controller/ApiController.php @@ -84,11 +84,13 @@ public function handle(Request $request): Response [$methodName, $inputDtoClass] = $this->getMethodAndInputDtoFQCN($requestHandlerInterface); $requestDto = null; + if ($inputDtoClass !== null) { $requestDto = $this->createRequestDto($request, $operation, $inputDtoClass); - $this->eventDispatcher->dispatch(new RequestDtoEvent($requestDto, $operationId, $specification)); } + $this->eventDispatcher->dispatch(new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler)); + $responseDto = $this->executeRequestHandler($requestHandler, $methodName, $requestDto); $this->eventDispatcher->dispatch(new ResponseDtoEvent($responseDto, $operationId, $specification)); diff --git a/src/Event/Server/RequestDtoEvent.php b/src/Event/Server/RequestDtoEvent.php index e063a102..de28ae19 100644 --- a/src/Event/Server/RequestDtoEvent.php +++ b/src/Event/Server/RequestDtoEvent.php @@ -5,6 +5,7 @@ namespace OnMoon\OpenApiServerBundle\Event\Server; use OnMoon\OpenApiServerBundle\Interfaces\Dto; +use OnMoon\OpenApiServerBundle\Interfaces\RequestHandler; use OnMoon\OpenApiServerBundle\Specification\Definitions\Specification; use Symfony\Contracts\EventDispatcher\Event; @@ -27,12 +28,14 @@ final class RequestDtoEvent extends Event private ?Dto $requestDto; private string $operationId; private Specification $specification; + private RequestHandler $requestHandler; - public function __construct(?Dto $requestDto, string $operationId, Specification $specification) + public function __construct(?Dto $requestDto, string $operationId, Specification $specification, RequestHandler $requestHandler) { - $this->requestDto = $requestDto; - $this->operationId = $operationId; - $this->specification = $specification; + $this->requestDto = $requestDto; + $this->operationId = $operationId; + $this->specification = $specification; + $this->requestHandler = $requestHandler; } public function getRequestDto(): ?Dto @@ -49,4 +52,9 @@ public function getSpecification(): Specification { return $this->specification; } + + public function getRequestHandler(): RequestHandler + { + return $this->requestHandler; + } } diff --git a/test/unit/Event/Server/RequestDtoEventTest.php b/test/unit/Event/Server/RequestDtoEventTest.php index 26076089..6126b144 100644 --- a/test/unit/Event/Server/RequestDtoEventTest.php +++ b/test/unit/Event/Server/RequestDtoEventTest.php @@ -7,6 +7,7 @@ use cebe\openapi\spec\OpenApi; use OnMoon\OpenApiServerBundle\Event\Server\RequestDtoEvent; use OnMoon\OpenApiServerBundle\Interfaces\Dto; +use OnMoon\OpenApiServerBundle\Interfaces\RequestHandler; use OnMoon\OpenApiServerBundle\Specification\Definitions\Specification; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; @@ -18,7 +19,7 @@ final class RequestDtoEventTest extends TestCase { public function testRequestDtoEventGettersReturnCorrectValues(): void { - $requestDto = new class () implements Dto { + $requestDto = new class () implements Dto { /** * @return mixed[] */ @@ -35,13 +36,32 @@ public static function fromArray(array $data): Dto return new self(); } }; - $operationId = '12345'; - $specification = new Specification([], new OpenApi([])); + $operationId = '12345'; + $specification = new Specification([], new OpenApi([])); + $requestHandler = new class () implements RequestHandler{ + }; - $requestDtoEvent = new RequestDtoEvent($requestDto, $operationId, $specification); + $requestDtoEvent = new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler); Assert::assertEquals($requestDto, $requestDtoEvent->getRequestDto()); Assert::assertEquals($operationId, $requestDtoEvent->getOperationId()); Assert::assertEquals($specification, $requestDtoEvent->getSpecification()); + Assert::assertEquals($requestHandler, $requestDtoEvent->getRequestHandler()); + } + + public function testRequestDtoEventGettersWhenRequestDtoNull(): void + { + $requestDto = null; + $operationId = '12345'; + $specification = new Specification([], new OpenApi([])); + $requestHandler = new class () implements RequestHandler{ + }; + + $requestDtoEvent = new RequestDtoEvent($requestDto, $operationId, $specification, $requestHandler); + + Assert::assertNull($requestDtoEvent->getRequestDto()); + Assert::assertEquals($operationId, $requestDtoEvent->getOperationId()); + Assert::assertEquals($specification, $requestDtoEvent->getSpecification()); + Assert::assertEquals($requestHandler, $requestDtoEvent->getRequestHandler()); } }