diff --git a/src/System/OpenApiAnalyser.php b/src/System/OpenApiAnalyser.php index 22691fb..1ae4d6d 100644 --- a/src/System/OpenApiAnalyser.php +++ b/src/System/OpenApiAnalyser.php @@ -9,7 +9,9 @@ use OpenApi\Annotations\Operation; use OpenApi\Attributes\Middleware; use OpenApi\Context; +use Override; use Zrnik\AttributeReflection\AttributeReflection; +use Zrnik\Zweist\ZweistConfiguration; use Zrnik\Zweist\ZweistRouteService; /** @@ -20,16 +22,17 @@ class OpenApiAnalyser extends Analysis /** @phpstan-var SlimRouteDataArrayShape[] */ private array $routes = []; - public function __construct() + public function __construct( + private readonly ZweistConfiguration $zweistConfiguration + ) { parent::__construct([], new Context()); } - #[\Override] + #[Override] public function addAnnotation(object $annotation, Context $context): void { if ($annotation instanceof Operation) { - /** @var class-string $controllerClass */ $controllerClass = sprintf( '%s\%s', @@ -64,6 +67,10 @@ public function addAnnotation(object $annotation, Context $context): void 'controller_method' => $method, 'middleware' => $middleware, ]; + + foreach ($this->zweistConfiguration->inspectors as $inspector) { + $inspector->inspect($controllerClass, $method, $annotation); + } } parent::addAnnotation($annotation, $context); diff --git a/src/System/OpenApiInspector.php b/src/System/OpenApiInspector.php new file mode 100644 index 0000000..cf8e270 --- /dev/null +++ b/src/System/OpenApiInspector.php @@ -0,0 +1,18 @@ +zweistConfiguration); $openApi = Generator::scan( $this->zweistConfiguration->openApiDefinitionPaths, diff --git a/tests/ExampleApplication/ExampleInspector.php b/tests/ExampleApplication/ExampleInspector.php new file mode 100644 index 0000000..cc1710b --- /dev/null +++ b/tests/ExampleApplication/ExampleInspector.php @@ -0,0 +1,23 @@ +container = new Container(); + + $this->container->set(LoggerInterface::class, $this->createMock(LoggerInterface::class)); + + $this->zweistConfiguration = new ZweistConfiguration( + [ + __DIR__ . '/ExampleApplication', + ], + __DIR__ . '/../temp/OpenApi.json', + __DIR__ . '/../temp/router.json', + [ + new ExampleInspector(), + ], + ); + } + + public function testInspectorCalled(): void + { + $zweistOpenApiGenerator = new ZweistOpenApiGenerator($this->zweistConfiguration, $this->container); + + /** @var Exception $exception */ + $exception = $this->assertExceptionThrown( + Exception::class, + fn() => $zweistOpenApiGenerator->generate(), + ); + + $this->assertSame(sprintf('%s called', ExampleInspector::class), $exception->getMessage()); + } +}