Skip to content

Commit

Permalink
Feat: support of custom annotation loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Besir Horáček authored and f3l1x committed Feb 23, 2024
1 parent e475373 commit 816aa4f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Core/DI/Plugin/CoreSchemaPlugin.php
Expand Up @@ -3,6 +3,7 @@
namespace Apitte\Core\DI\Plugin;

use Apitte\Core\DI\Loader\DoctrineAnnotationLoader;
use Apitte\Core\DI\Loader\ILoader;
use Apitte\Core\DI\Loader\NeonLoader;
use Apitte\Core\Schema\SchemaBuilder;
use Apitte\Core\Schema\Serialization\ArrayHydrator;
Expand Down Expand Up @@ -63,6 +64,7 @@ protected function getConfigSchema(): Schema
'loaders' => Expect::structure([
'annotations' => Expect::structure([
'enable' => Expect::bool(true),
'loader' => Expect::string(DoctrineAnnotationLoader::class),
]),
'neon' => Expect::structure([
'enable' => Expect::bool(false),
Expand Down Expand Up @@ -112,10 +114,17 @@ 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 (!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, ILoader::class)) {
throw new \RuntimeException(sprintf('Annotation loader class %s must be subclass of %s', $loaders->annotations->loader, ILoader::class));
}

$loader = new $loaders->annotations->loader($this->getContainerBuilder());
$builder = $loader->load($builder);
}

Expand Down

0 comments on commit 816aa4f

Please sign in to comment.