Skip to content

Commit c3275d9

Browse files
committed
bug #44110 [FrameworkBundle] Fix default PHP attributes support in validation and serializer configuration when doctrine/annotations is not installed with PHP 8 (fancyweb)
This PR was merged into the 5.3 branch. Discussion ---------- [FrameworkBundle] Fix default PHP attributes support in validation and serializer configuration when doctrine/annotations is not installed with PHP 8 | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Afrer upgrading to PHP 8 and using real PHP attributes, I noticed there were no validation metadata for my classes anymore. Before: - Full default FWB validator config - PHP 7.4 - Constraints in my code are declared as PHPDoc annotation (the old way) - doctrine/annotations is required in composer.json After: - Full default FWB validator config - PHP 8.0 - Constraints in my code are declared as real PHP attributes - doctrine/annotations has been removed from composer.json because I don't need it anymore I expect the migration to be transparent, ie not having to do any change in the config to switch from PHPDoc annotations to real PHP attributes. However, `validation.enable_annotations` does not default to true anymore after the migration so here is the fix. WDYT? Commits ------- c9be9704f0 [FrameworkBundle] Fix default PHP attributes support in validation and serializer configuration when doctrine/annotations is not installed with PHP 8
2 parents 4999e37 + 68b2b3c commit c3275d9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

DependencyInjection/Configuration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
859859
->{$enableIfStandalone('symfony/validator', Validation::class)}()
860860
->children()
861861
->scalarNode('cache')->end()
862-
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && $willBeAvailable('doctrine/annotations', Annotation::class, 'symfony/validator') ? 'defaultTrue' : 'defaultFalse'}()->end()
862+
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && (\PHP_VERSION_ID >= 80000 || $willBeAvailable('doctrine/annotations', Annotation::class, 'symfony/validator')) ? 'defaultTrue' : 'defaultFalse'}()->end()
863863
->arrayNode('static_method')
864864
->defaultValue(['loadValidatorMetadata'])
865865
->prototype('scalar')->end()
@@ -942,8 +942,8 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
942942

943943
private function addAnnotationsSection(ArrayNodeDefinition $rootNode, callable $willBeAvailable)
944944
{
945-
$doctrineCache = $willBeAvailable('doctrine/cache', Cache::class, 'doctrine/annotation');
946-
$psr6Cache = $willBeAvailable('symfony/cache', PsrCachedReader::class, 'doctrine/annotation');
945+
$doctrineCache = $willBeAvailable('doctrine/cache', Cache::class, 'doctrine/annotations');
946+
$psr6Cache = $willBeAvailable('symfony/cache', PsrCachedReader::class, 'doctrine/annotations');
947947

948948
$rootNode
949949
->children()
@@ -968,7 +968,7 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
968968
->info('serializer configuration')
969969
->{$enableIfStandalone('symfony/serializer', Serializer::class)}()
970970
->children()
971-
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && $willBeAvailable('doctrine/annotations', Annotation::class, 'symfony/serializer') ? 'defaultTrue' : 'defaultFalse'}()->end()
971+
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && (\PHP_VERSION_ID >= 80000 || $willBeAvailable('doctrine/annotations', Annotation::class, 'symfony/serializer')) ? 'defaultTrue' : 'defaultFalse'}()->end()
972972
->scalarNode('name_converter')->end()
973973
->scalarNode('circular_reference_handler')->end()
974974
->scalarNode('max_depth_handler')->end()

0 commit comments

Comments
 (0)