Skip to content

Commit

Permalink
feature #39022 [FrameworkBundle] Allow to use attribute-based configu…
Browse files Browse the repository at this point in the history
…ration of routing/serializer without doctrine/annotations (derrabus)

This PR was merged into the 5.2-dev branch.

Discussion
----------

 [FrameworkBundle] Allow to use attribute-based configuration of routing/serializer without doctrine/annotations

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

Follows #37474, #38525

Currently, we need `doctrine/annotations` to be installed in order to configure routing and serializer via PHP attributes. Given that for both components we can already replace Doctrine Annotations completely, I'd like to get rid of that limitation.

Commits
-------

e5492e2 [FrameworkBundle] Configure PHP Attributes without doctrine/annotations.
  • Loading branch information
derrabus committed Nov 7, 2020
2 parents 50c7c3d + e5492e2 commit 7b4d22f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Expand Up @@ -965,11 +965,11 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
->replaceArgument(0, $config['default_uri']);
}

if ($this->annotationsConfigEnabled) {
if (\PHP_VERSION_ID >= 80000 || $this->annotationsConfigEnabled) {
$container->register('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
->setPublic(false)
->addTag('routing.loader', ['priority' => -10])
->addArgument(new Reference('annotation_reader'));
->addArgument(new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE));

$container->register('routing.loader.annotation.directory', AnnotationDirectoryLoader::class)
->setPublic(false)
Expand Down Expand Up @@ -1564,13 +1564,13 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder

$serializerLoaders = [];
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
if (!$this->annotationsConfigEnabled) {
if (\PHP_VERSION_ID < 80000 && !$this->annotationsConfigEnabled) {
throw new \LogicException('"enable_annotations" on the serializer cannot be set as Annotations support is disabled.');
}

$annotationLoader = new Definition(
'Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader',
[new Reference('annotation_reader')]
[new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
);
$annotationLoader->setPublic(false);

Expand Down
Expand Up @@ -1232,7 +1232,7 @@ public function testSerializerMapping()
$projectDir = $container->getParameter('kernel.project_dir');
$configDir = __DIR__.'/Fixtures/TestBundle/Resources/config';
$expectedLoaders = [
new Definition(AnnotationLoader::class, [new Reference('annotation_reader')]),
new Definition(AnnotationLoader::class, [new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)]),
new Definition(XmlFileLoader::class, [$configDir.'/serialization.xml']),
new Definition(YamlFileLoader::class, [$configDir.'/serialization.yml']),
new Definition(YamlFileLoader::class, [$projectDir.'/config/serializer/foo.yml']),
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Expand Up @@ -29,7 +29,7 @@
"symfony/polyfill-php80": "^1.15",
"symfony/filesystem": "^4.4|^5.0",
"symfony/finder": "^4.4|^5.0",
"symfony/routing": "^5.1"
"symfony/routing": "^5.2"
},
"require-dev": {
"doctrine/annotations": "~1.7",
Expand Down

0 comments on commit 7b4d22f

Please sign in to comment.