Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: support of custom annotation loader #206

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Core/DI/Plugin/CoreSchemaPlugin.php
Original file line number Diff line number Diff line change
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 @@
'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 @@
{
$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));

Check warning on line 120 in src/Core/DI/Plugin/CoreSchemaPlugin.php

View check run for this annotation

Codecov / codecov/patch

src/Core/DI/Plugin/CoreSchemaPlugin.php#L120

Added line #L120 was not covered by tests
}

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));

Check warning on line 124 in src/Core/DI/Plugin/CoreSchemaPlugin.php

View check run for this annotation

Codecov / codecov/patch

src/Core/DI/Plugin/CoreSchemaPlugin.php#L124

Added line #L124 was not covered by tests
}

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

Expand Down
Loading