Skip to content

Commit f01ba2e

Browse files
committed
feature #51425 [FrameworkBundle][Validator] Deprecate annotation occurrences (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle][Validator] Deprecate annotation occurrences | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Part of symfony/symfony#51381 | License | MIT | Doc PR | - * Deprecate `framework.validation.enable_annotations` in favor of `framework.validation.enable_attributes` * Deprecate `framework.serializer.enable_annotations` in favor of use `framework.serializer.enable_attributes` * Deprecate `ValidatorBuilder::enableAnnotationMapping()` in favor of `ValidatorBuilder::enableAttributeMapping()` * Deprecate `ValidatorBuilder::disableAnnotationMapping()` in favor of `ValidatorBuilder::disableAttributeMapping()` * Deprecate `AnnotationLoader` in favor of `AttributeLoader` Commits ------- 2e1e805f89 [FrameworkBundle][Validator] Deprecate annotation occurrences
2 parents 405cd3c + c543998 commit f01ba2e

24 files changed

+67
-37
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ CHANGELOG
2222
* Deprecate not setting the `framework.uid.default_uuid_version` config option; it will default to `7` in 7.0
2323
* Deprecate not setting the `framework.uid.time_based_uuid_version` config option; it will default to `7` in 7.0
2424
* Deprecate not setting the `framework.validation.email_validation_mode` config option; it will default to `html5` in 7.0
25+
* Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead
26+
* Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead
2527

2628
6.3
2729
---

DependencyInjection/Configuration.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,16 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10321032
trigger_deprecation('symfony/framework-bundle', '6.4', 'Not setting the "framework.validation.email_validation_mode" config option is deprecated. It will default to "html5" in 7.0.');
10331033
}
10341034

1035+
if (isset($v['enable_annotations'])) {
1036+
trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.validation" is deprecated. Use the "enable_attributes" option instead.');
1037+
1038+
if (!isset($v['enable_attributes'])) {
1039+
$v['enable_attributes'] = $v['enable_annotations'];
1040+
} else {
1041+
throw new LogicException('The "enable_annotations" and "enable_attributes" options at path "framework.validation" must not be both set. Only the "enable_attributes" option must be used.');
1042+
}
1043+
}
1044+
10351045
return $v;
10361046
})
10371047
->end()
@@ -1041,7 +1051,8 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10411051
->{$enableIfStandalone('symfony/validator', Validation::class)}()
10421052
->children()
10431053
->scalarNode('cache')->end()
1044-
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
1054+
->booleanNode('enable_annotations')->end()
1055+
->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
10451056
->arrayNode('static_method')
10461057
->defaultValue(['loadValidatorMetadata'])
10471058
->prototype('scalar')->end()
@@ -1147,10 +1158,25 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
11471158
$rootNode
11481159
->children()
11491160
->arrayNode('serializer')
1161+
->validate()
1162+
->always(function ($v) {
1163+
if (isset($v['enable_annotations'])) {
1164+
trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.serializer" is deprecated. Use the "enable_attributes" option instead.');
1165+
1166+
if (!isset($v['enable_attributes'])) {
1167+
$v['enable_attributes'] = $v['enable_annotations'];
1168+
} else {
1169+
throw new LogicException('The "enable_annotations" and "enable_attributes" options at path "framework.serializer" must not be both set. Only the "enable_attributes" option must be used.');
1170+
}
1171+
}
1172+
1173+
return $v;
1174+
})->end()
11501175
->info('serializer configuration')
11511176
->{$enableIfStandalone('symfony/serializer', Serializer::class)}()
11521177
->children()
1153-
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
1178+
->booleanNode('enable_annotations')->end()
1179+
->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
11541180
->scalarNode('name_converter')->end()
11551181
->scalarNode('circular_reference_handler')->end()
11561182
->scalarNode('max_depth_handler')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,8 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
16571657
$definition = $container->findDefinition('validator.email');
16581658
$definition->replaceArgument(0, $config['email_validation_mode']);
16591659

1660-
if (\array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
1661-
$validatorBuilder->addMethodCall('enableAnnotationMapping', [true]);
1660+
if (\array_key_exists('enable_attributes', $config) && $config['enable_attributes']) {
1661+
$validatorBuilder->addMethodCall('enableAttributeMapping', [true]);
16621662
if ($this->isInitializedConfigEnabled('annotations') && method_exists(ValidatorBuilder::class, 'setDoctrineAnnotationReader')) {
16631663
$validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]);
16641664
}
@@ -1930,7 +1930,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19301930
}
19311931

19321932
$serializerLoaders = [];
1933-
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
1933+
if (isset($config['enable_attributes']) && $config['enable_attributes']) {
19341934
if ($container->getParameter('kernel.debug')) {
19351935
$container->removeDefinition('serializer.mapping.cache_class_metadata_factory');
19361936
}

Resources/config/schema/symfony-1.0.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
<xsd:attribute name="enabled" type="xsd:boolean" />
270270
<xsd:attribute name="cache" type="xsd:string" />
271271
<xsd:attribute name="enable-annotations" type="xsd:boolean" />
272+
<xsd:attribute name="enable-attributes" type="xsd:boolean" />
272273
<xsd:attribute name="static-method" type="xsd:boolean" />
273274
<xsd:attribute name="translation-domain" type="xsd:string" />
274275
<xsd:attribute name="strict-email" type="xsd:boolean" />
@@ -322,6 +323,7 @@
322323
</xsd:choice>
323324
<xsd:attribute name="enabled" type="xsd:boolean" />
324325
<xsd:attribute name="enable-annotations" type="xsd:boolean" />
326+
<xsd:attribute name="enable-attributes" type="xsd:boolean" />
325327
<xsd:attribute name="name-converter" type="xsd:string" />
326328
<xsd:attribute name="circular-reference-handler" type="xsd:string" />
327329
<xsd:attribute name="max-depth-handler" type="xsd:string" />

Tests/CacheWarmer/ValidatorCacheWarmerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testWarmUp()
2626
$validatorBuilder->addXmlMapping(__DIR__.'/../Fixtures/Validation/Resources/person.xml');
2727
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/author.yml');
2828
$validatorBuilder->addMethodMapping('loadValidatorMetadata');
29-
$validatorBuilder->enableAnnotationMapping();
29+
$validatorBuilder->enableAttributeMapping();
3030

3131
$file = sys_get_temp_dir().'/cache-validator.php';
3232
@unlink($file);
@@ -46,7 +46,7 @@ public function testWarmUpWithAnnotations()
4646
{
4747
$validatorBuilder = new ValidatorBuilder();
4848
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/categories.yml');
49-
$validatorBuilder->enableAnnotationMapping();
49+
$validatorBuilder->enableAttributeMapping();
5050

5151
$file = sys_get_temp_dir().'/cache-validator-with-annotations.php';
5252
@unlink($file);

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ protected static function getBundleDefaultConfig()
591591
],
592592
'validation' => [
593593
'enabled' => !class_exists(FullStack::class),
594-
'enable_annotations' => !class_exists(FullStack::class),
594+
'enable_attributes' => !class_exists(FullStack::class),
595595
'static_method' => ['loadValidatorMetadata'],
596596
'translation_domain' => 'validators',
597597
'mapping' => [
@@ -612,7 +612,7 @@ protected static function getBundleDefaultConfig()
612612
'serializer' => [
613613
'default_context' => ['foo' => 'bar', JsonDecode::DETAILED_ERROR_MESSAGES => true],
614614
'enabled' => true,
615-
'enable_annotations' => !class_exists(FullStack::class),
615+
'enable_attributes' => !class_exists(FullStack::class),
616616
'mapping' => ['paths' => []],
617617
],
618618
'property_access' => [

Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
'annotations' => false,
6464
'serializer' => [
6565
'enabled' => true,
66-
'enable_annotations' => true,
66+
'enable_attributes' => true,
6767
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case',
6868
'circular_reference_handler' => 'my.circular.reference.handler',
6969
'max_depth_handler' => 'my.max.depth.handler',

Tests/DependencyInjection/Fixtures/php/serializer_mapping.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'php_errors' => ['log' => true],
77
'annotations' => false,
88
'serializer' => [
9-
'enable_annotations' => true,
9+
'enable_attributes' => true,
1010
'mapping' => [
1111
'paths' => [
1212
'%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files',

Tests/DependencyInjection/Fixtures/php/serializer_mapping_without_annotations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'handle_all_throwables' => true,
77
'php_errors' => ['log' => true],
88
'serializer' => [
9-
'enable_annotations' => false,
9+
'enable_attributes' => false,
1010
'mapping' => [
1111
'paths' => [
1212
'%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files',

Tests/DependencyInjection/Fixtures/php/validation_annotations.php renamed to Tests/DependencyInjection/Fixtures/php/validation_attributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'secret' => 's3cr3t',
99
'validation' => [
1010
'enabled' => true,
11-
'enable_annotations' => true,
11+
'enable_attributes' => true,
1212
'email_validation_mode' => 'html5',
1313
],
1414
]);

0 commit comments

Comments
 (0)