From c41b0c2a1d78992e50fc63f62fead5c5c1cc2b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Besir=20Hora=CC=81c=CC=8Cek?= Date: Thu, 1 Feb 2024 13:49:04 +0100 Subject: [PATCH] Feat: support of custom annotation loader --- src/Core/DI/Plugin/CoreSchemaPlugin.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Core/DI/Plugin/CoreSchemaPlugin.php b/src/Core/DI/Plugin/CoreSchemaPlugin.php index 74f8e3b..000f7bf 100644 --- a/src/Core/DI/Plugin/CoreSchemaPlugin.php +++ b/src/Core/DI/Plugin/CoreSchemaPlugin.php @@ -63,6 +63,7 @@ protected function getConfigSchema(): Schema 'loaders' => Expect::structure([ 'annotations' => Expect::structure([ 'enable' => Expect::bool(true), + 'loader' => Expect::string(), ]), 'neon' => Expect::structure([ 'enable' => Expect::bool(false), @@ -112,10 +113,21 @@ protected function loadSchema(SchemaBuilder $builder): SchemaBuilder { $loaders = $this->config->loaders; - //TODO - resolve limitation - Controller defined by one of loaders cannot be modified by other loaders - if ($loaders->annotations->enable) { - $loader = new DoctrineAnnotationLoader($this->getContainerBuilder()); + if ($loaders->annotations->loader) { + + if (!class_exists($loaders->annotations->loader)) { + throw new \RuntimeException(sprintf('Annotation loader class %s does not exist', $loaders->annotations->loader)); + } + + if (!is_subclass_of($loaders->annotations->loader, DoctrineAnnotationLoader::class)) { + throw new \RuntimeException(sprintf('Annotation loader class %s must be subclass of %s', $loaders->annotations->loader, DoctrineAnnotationLoader::class)); + } + + $loader = new $loaders->annotations->loader($this->getContainerBuilder()); + } else { + $loader = new DoctrineAnnotationLoader($this->getContainerBuilder()); + } $builder = $loader->load($builder); }