Skip to content

Commit 816aa4f

Browse files
Petr Besir Horáčekf3l1x
authored andcommitted
Feat: support of custom annotation loader
1 parent e475373 commit 816aa4f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Core/DI/Plugin/CoreSchemaPlugin.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Apitte\Core\DI\Plugin;
44

55
use Apitte\Core\DI\Loader\DoctrineAnnotationLoader;
6+
use Apitte\Core\DI\Loader\ILoader;
67
use Apitte\Core\DI\Loader\NeonLoader;
78
use Apitte\Core\Schema\SchemaBuilder;
89
use Apitte\Core\Schema\Serialization\ArrayHydrator;
@@ -63,6 +64,7 @@ protected function getConfigSchema(): Schema
6364
'loaders' => Expect::structure([
6465
'annotations' => Expect::structure([
6566
'enable' => Expect::bool(true),
67+
'loader' => Expect::string(DoctrineAnnotationLoader::class),
6668
]),
6769
'neon' => Expect::structure([
6870
'enable' => Expect::bool(false),
@@ -112,10 +114,17 @@ protected function loadSchema(SchemaBuilder $builder): SchemaBuilder
112114
{
113115
$loaders = $this->config->loaders;
114116

115-
//TODO - resolve limitation - Controller defined by one of loaders cannot be modified by other loaders
116-
117117
if ($loaders->annotations->enable) {
118-
$loader = new DoctrineAnnotationLoader($this->getContainerBuilder());
118+
119+
if (!class_exists($loaders->annotations->loader)) {
120+
throw new \RuntimeException(sprintf('Annotation loader class %s does not exist', $loaders->annotations->loader));
121+
}
122+
123+
if (!is_subclass_of($loaders->annotations->loader, ILoader::class)) {
124+
throw new \RuntimeException(sprintf('Annotation loader class %s must be subclass of %s', $loaders->annotations->loader, ILoader::class));
125+
}
126+
127+
$loader = new $loaders->annotations->loader($this->getContainerBuilder());
119128
$builder = $loader->load($builder);
120129
}
121130

0 commit comments

Comments
 (0)