8000 [FrameworkBundle][Validator] Deprecate annotation occurrences · symfony/symfony@1723d35 · GitHub
[go: up one dir, main page]

Skip to content
  • Insights
  • Commit 1723d35

    Browse files
    [FrameworkBundle][Validator] Deprecate annotation occurrences
    1 parent 9a0f178 commit 1723d35

    File tree

    101 files changed

    +600
    -188
    lines changed

    Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    101 files changed

    +600
    -188
    lines changed

    UPGRADE-6.4.md

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -93,6 +93,8 @@ FrameworkBundle
    9393
    * Deprecate not setting the `framework.uid.default_uuid_version` config option; it will default to `7` in 7.0
    9494
    * Deprecate not setting the `framework.uid.time_based_uuid_version` config option; it will default to `7` in 7.0
    9595
    * Deprecate not setting the `framework.validation.email_validation_mode` config option; it will default to `html5` in 7.0
    96+
    * Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead
    97+
    * Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead
    9698

    9799
    HttpFoundation
    98100
    --------------
    @@ -157,3 +159,6 @@ Validator
    157159
    * Deprecate passing an annotation reader to the constructor signature of `AnnotationLoader`
    158160
    * Deprecate `ValidatorBuilder::setDoctrineAnnotationReader()`
    159161
    * Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()`
    162+
    * Deprecate `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead
    163+
    * Deprecate `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead
    164+
    * Deprecate `AnnotationLoader`, use `AttributeLoader` instead

    src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityTest.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,14 +14,14 @@
    1414
    use PHPUnit\Framework\TestCase;
    1515
    use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
    1616
    use Symfony\Component\Validator\Mapping\ClassMetadata;
    17-
    use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
    17+
    use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
    1818

    1919
    class UniqueEntityTest extends TestCase
    2020
    {
    2121
    public function testAttributeWithDefaultProperty()
    2222
    {
    2323
    $metadata = new ClassMetadata(UniqueEntityDummyOne::class);
    24-
    $loader = new AnnotationLoader();
    24+
    $loader = new AttributeLoader();
    2525
    self::assertTrue($loader->loadClassMetadata($metadata));
    2626

    2727
    /** @var UniqueEntity $constraint */
    @@ -35,7 +35,7 @@ public function testAttributeWithDefaultProperty()
    3535
    public function testAttributeWithCustomizedService()
    3636
    {
    3737
    $metadata = new ClassMetadata(UniqueEntityDummyTwo::class);
    38-
    $loader = new AnnotationLoader();
    38+
    $loader = new AttributeLoader();
    3939
    self::assertTrue($loader->loadClassMetadata($metadata));
    4040

    4141
    /** @var UniqueEntity $constraint */
    @@ -50,7 +50,7 @@ public function testAttributeWithCustomizedService()
    5050
    public function testAttributeWithGroupsAndPaylod()
    5151
    {
    5252
    $metadata = new ClassMetadata(UniqueEntityDummyThree::class);
    53-
    $loader = new AnnotationLoader();
    53+
    $loader = new AttributeLoader();
    5454
    self::assertTrue($loader->loadClassMetadata($metadata));
    5555

    5656
    /** @var UniqueEntity $constraint */

    src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -39,7 +39,7 @@ class DoctrineLoaderTest extends TestCase
    3939
    public function testLoadClassMetadata()
    4040
    {
    4141
    $validator = Validation::createValidatorBuilder()
    42-
    ->enableAnnotationMapping(true)
    42+
    ->enableAttributeMapping()
    4343
    ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
    4444
    ->getValidator()
    4545
    ;
    @@ -142,7 +142,7 @@ public function testExtractEnum()
    142142
    {
    143143
    $validator = Validation::createValidatorBuilder()
    144144
    ->addMethodMapping('loadValidatorMetadata')
    145-
    ->enableAnnotationMapping(true)
    145+
    ->enableAttributeMapping()
    146146
    ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
    147147
    ->getValidator()
    148148
    ;
    @@ -159,7 +159,7 @@ public function testExtractEnum()
    159159
    public function testFieldMappingsConfiguration()
    160160
    {
    161161
    $validator = Validation::createValidatorBuilder()
    162-
    ->enableAnnotationMapping(true)
    162+
    ->enableAttributeMapping()
    163163
    ->addXmlMappings([__DIR__.'/../Resources/validator/BaseUser.xml'])
    164164
    ->addLoader(
    165165
    new DoctrineLoader(
    @@ -200,7 +200,7 @@ public static function regexpProvider(): array
    200200
    public function testClassNoAutoMapping()
    201201
    {
    202202
    $validator = Validation::createValidatorBuilder()
    203-
    ->enableAnnotationMapping(true)
    203+
    ->enableAttributeMapping()
    204204
    ->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{.*}'))
    205205
    ->getValidator();
    206206

    src/Symfony/Bridge/Doctrine/composer.json

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -41,7 +41,7 @@
    4141
    "symfony/stopwatch": "^5.4|^6.0|^7.0",
    4242
    "symfony/translation": "^5.4|^6.0|^7.0",
    4343
    "symfony/uid": "^5.4|^6.0|^7.0",
    44-
    "symfony/validator": "^5.4.25|~6.2.12|^6.3.1|^7.0",
    44+
    "symfony/validator": "^6.4|^7.0",
    4545
    "symfony/var-dumper": "^5.4|^6.0|^7.0",
    4646
    "doctrine/collections": "^1.0|^2.0",
    4747
    "doctrine/data-fixtures": "^1.1",
    @@ -63,7 +63,7 @@
    6363
    "symfony/property-info": "<5.4",
    6464
    "symfony/security-bundle": "<5.4",
    6565
    "symfony/security-core": "<6.4",
    66-
    "symfony/validator": "<5.4.25|>=6,<6.2.12|>=6.3,<6.3.1"
    66+
    "symfony/validator": "<6.4"
    6767
    },
    6868
    "autoload": {
    6969
    "psr-4": { "Symfony\\Bridge\\Doctrine\\": "" },

    src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

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

    2527
    6.3
    2628
    ---

    src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

    Lines changed: 28 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1024,6 +1024,16 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
    10241024
    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.');
    10251025
    }
    10261026

    1027+
    if (isset($v['enable_annotations'])) {
    1028+
    trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.validation" is deprecated. Use the "enable_attributes" option instead.');
    1029+
    1030+
    if (!isset($v['enable_attributes'])) {
    1031+
    $v['enable_attributes'] = $v['enable_annotations'];
    1032+
    } else {
    1033+
    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.');
    1034+
    }
    1035+
    }
    1036+
    10271037
    return $v;
    10281038
    })
    10291039
    ->end()
    @@ -1033,7 +1043,8 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
    10331043
    ->{$enableIfStandalone('symfony/validator', Validation::class)}()
    10341044
    ->children()
    10351045
    ->scalarNode('cache')->end()
    1036-
    ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
    1046+
    ->booleanNode('enable_annotations')->end()
    1047+
    ->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
    10371048
    ->arrayNode('static_method')
    10381049
    ->defaultValue(['loadValidatorMetadata'])
    10391050
    ->prototype('scalar')->end()
    @@ -1139,10 +1150,25 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
    11391150
    $rootNode
    11401151
    ->children()
    11411152
    ->arrayNode('serializer')
    1153+
    ->validate()
    1154+
    ->always(function ($v) {
    1155+
    if (isset($v['enable_annotations'])) {
    1156+
    trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.serializer" is deprecated. Use the "enable_attributes" option instead.');
    1157+
    1158+
    if (!isset($v['enable_attributes'])) {
    1159+
    $v['enable_attributes'] = $v['enable_annotations'];
    1160+
    } else {
    1161+
    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.');
    1162+
    }
    1163+
    }
    1164+
    1165+
    return $v;
    1166+
    })->end()
    11421167
    ->info('serializer configuration')
    11431168
    ->{$enableIfStandalone('symfony/serializer', Serializer::class)}()
    11441169
    ->children()
    1145-
    ->booleanNode('enable_annotations')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
    1170+
    ->booleanNode('enable_annotations')->end()
    1171+
    ->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
    11461172
    ->scalarNode('name_converter')->end()
    11471173
    ->scalarNode('circular_reference_handler')->end()
    11481174
    ->scalarNode('max_depth_handler')->end()

    src/Symfony/Bundle/FrameworkBundle/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
    }

    src/Symfony/Bundle/FrameworkBundle/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" />

    src/Symfony/Bundle/FrameworkBundle/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);

    src/Symfony/Bundle/FrameworkBundle/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' => [

    0 commit comments

    Comments
     (0)
    0