|
3 | 3 | namespace Apitte\Core\DI\Plugin; |
4 | 4 |
|
5 | 5 | use Apitte\Core\DI\Loader\DoctrineAnnotationLoader; |
| 6 | +use Apitte\Core\DI\Loader\ILoader; |
6 | 7 | use Apitte\Core\DI\Loader\NeonLoader; |
7 | 8 | use Apitte\Core\Schema\SchemaBuilder; |
8 | 9 | use Apitte\Core\Schema\Serialization\ArrayHydrator; |
@@ -63,6 +64,7 @@ protected function getConfigSchema(): Schema |
63 | 64 | 'loaders' => Expect::structure([ |
64 | 65 | 'annotations' => Expect::structure([ |
65 | 66 | 'enable' => Expect::bool(true), |
| 67 | + 'loader' => Expect::string(DoctrineAnnotationLoader::class), |
66 | 68 | ]), |
67 | 69 | 'neon' => Expect::structure([ |
68 | 70 | 'enable' => Expect::bool(false), |
@@ -112,10 +114,17 @@ protected function loadSchema(SchemaBuilder $builder): SchemaBuilder |
112 | 114 | { |
113 | 115 | $loaders = $this->config->loaders; |
114 | 116 |
|
115 | | - //TODO - resolve limitation - Controller defined by one of loaders cannot be modified by other loaders |
116 | | - |
117 | 117 | 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()); |
119 | 128 | $builder = $loader->load($builder); |
120 | 129 | } |
121 | 130 |
|
|
0 commit comments