Skip to content

Commit ac6c303

Browse files
committed
[Validator] Deprecate annotations in favor of attributes
1 parent b15e258 commit ac6c303

Some content is hidden

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

42 files changed

+385
-164
lines changed

UPGRADE-6.4.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,11 @@ Security
6969
* `UserValueResolver` no longer implements `ArgumentValueResolverInterface`
7070
* Make `PersistentToken` immutable
7171
* Deprecate accepting only `DateTime` for `TokenProviderInterface::updateToken()`, use `DateTimeInterface` instead
72+
73+
Validator
74+
---------
75+
76+
* Deprecate Doctrine annotations support in favor of native attributes
77+
* Deprecate passing an annotation reader to the constructor signature of `AnnotationLoader`
78+
* Deprecate `ValidatorBuilder::setDoctrineAnnotationReader()`
79+
* Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()`

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use Symfony\Component\Validator\Mapping\ClassMetadata;
2929
use Symfony\Component\Validator\Mapping\PropertyMetadata;
3030
use Symfony\Component\Validator\Mapping\TraversalStrategy;
31-
use Symfony\Component\Validator\Tests\Fixtures\Entity;
31+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
3232
use Symfony\Component\Validator\Validation;
3333

3434
/**
@@ -40,7 +40,6 @@ public function testLoadClassMetadata()
4040
{
4141
$validator = Validation::createValidatorBuilder()
4242
->enableAnnotationMapping(true)
43-
->addDefaultDoctrineAnnotationReader()
4443
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
4544
->getValidator()
4645
;
@@ -144,7 +143,6 @@ public function testExtractEnum()
144143
$validator = Validation::createValidatorBuilder()
145144
->addMethodMapping('loadValidatorMetadata')
146145
->enableAnnotationMapping(true)
147-
->addDefaultDoctrineAnnotationReader()
148146
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
149147
->getValidator()
150148
;
@@ -162,7 +160,6 @@ public function testFieldMappingsConfiguration()
162160
{
163161
$validator = Validation::createValidatorBuilder()
164162
->enableAnnotationMapping(true)
165-
->addDefaultDoctrineAnnotationReader()
166163
->addXmlMappings([__DIR__.'/../Resources/validator/BaseUser.xml'])
167164
->addLoader(
168165
new DoctrineLoader(
@@ -204,7 +201,6 @@ public function testClassNoAutoMapping()
204201
{
205202
$validator = Validation::createValidatorBuilder()
206203
->enableAnnotationMapping(true)
207-
->addDefaultDoctrineAnnotationReader()
208204
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{.*}'))
209205
->getValidator();
210206

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@
4343
"symfony/uid": "^5.4|^6.0|^7.0",
4444
"symfony/validator": "^5.4.25|~6.2.12|^6.3.1|^7.0",
4545
"symfony/var-dumper": "^5.4|^6.0|^7.0",
46-
"doctrine/annotations": "^1.13.1|^2",
4746
"doctrine/collections": "^1.0|^2.0",
4847
"doctrine/data-fixtures": "^1.1",
4948
"doctrine/dbal": "^2.13.1|^3.0",
5049
"doctrine/orm": "^2.15",
5150
"psr/log": "^1|^2|^3"
5251
},
5352
"conflict": {
54-
"doctrine/annotations": "<1.13.1",
5553
"doctrine/dbal": "<2.13.1",
5654
"doctrine/lexer": "<1.1",
5755
"doctrine/orm": "<2.15",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
182182
use Symfony\Component\Validator\ObjectInitializerInterface;
183183
use Symfony\Component\Validator\Validation;
184+
use Symfony\Component\Validator\ValidatorBuilder;
184185
use Symfony\Component\Webhook\Controller\WebhookController;
185186
use Symfony\Component\WebLink\HttpHeaderSerializer;
186187
use Symfony\Component\Workflow;
@@ -1609,7 +1610,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
16091610

16101611
if (\array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
16111612
$validatorBuilder->addMethodCall('enableAnnotationMapping', [true]);
1612-
if ($this->isInitializedConfigEnabled('annotations')) {
1613+
if ($this->isInitializedConfigEnabled('annotations') && \method_exists(ValidatorBuilder::class, 'setDoctrineAnnotationReader')) {
16131614
$validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]);
16141615
}
16151616
}

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(true)->addDefaultDoctrineAnnotationReader();
29+
$validatorBuilder->enableAnnotationMapping();
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(true)->addDefaultDoctrineAnnotationReader();
49+
$validatorBuilder->enableAnnotationMapping();
5050

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

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
8282
use Symfony\Component\Validator\Validation;
8383
use Symfony\Component\Validator\Validator\ValidatorInterface;
84+
use Symfony\Component\Validator\ValidatorBuilder;
8485
use Symfony\Component\Webhook\Client\RequestParser;
8586
use Symfony\Component\Webhook\Controller\WebhookController;
8687
use Symfony\Component\Workflow;
@@ -1308,12 +1309,17 @@ public function testValidationLegacyAnnotations()
13081309

13091310
$this->assertCount(8, $calls);
13101311
$this->assertSame('enableAnnotationMapping', $calls[4][0]);
1311-
$this->assertSame('setDoctrineAnnotationReader', $calls[5][0]);
1312-
$this->assertEquals([new Reference('annotation_reader')], $calls[5][1]);
1313-
$this->assertSame('addMethodMapping', $calls[6][0]);
1314-
$this->assertSame(['loadValidatorMetadata'], $calls[6][1]);
1315-
$this->assertSame('setMappingCache', $calls[7][0]);
1316-
$this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[7][1]);
1312+
if (\method_exists(ValidatorBuilder::class, 'setDoctrineAnnotationReader')) {
1313+
$this->assertSame('setDoctrineAnnotationReader', $calls[5][0]);
1314+
$this->assertEquals([new Reference('annotation_reader')], $calls[5][1]);
1315+
$i = 6;
1316+
} else {
1317+
$i = 5;
1318+
}
1319+
$this->assertSame('addMethodMapping', $calls[$i][0]);
1320+
$this->assertSame(['loadValidatorMetadata'], $calls[$i][1]);
1321+
$this->assertSame('setMappingCache', $calls[++$i][0]);
1322+
$this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[$i][1]);
13171323
// no cache this time
13181324
}
13191325

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Category.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class Category
1010

1111
public $id;
1212

13-
/**
14-
* @Assert\Type("string")
15-
*/
13+
#[Assert\Type('string')]
1614
public $name;
1715
}

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ CHANGELOG
66

77
* Allow single integer for the `versions` option of the `Uuid` constraint
88
* Allow single constraint to be passed to the `constraints` option of the `When` constraint
9+
* Deprecate Doctrine annotations support in favor of native attributes
10+
* Deprecate passing an annotation reader to the constructor signature of `AnnotationLoader`
11+
* Deprecate `ValidatorBuilder::setDoctrineAnnotationReader()`
12+
* Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()`
913

1014
6.3
1115
---

src/Symfony/Component/Validator/Constraints/GroupSequence.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
*
2929
* When adding metadata to a class, you can override the "Default" group of
3030
* that class with a group sequence:
31-
* /**
32-
* * @GroupSequence({"Address", "Strict"})
33-
* *\/
31+
* #[GroupSequence(['Address', 'Strict'])]
3432
* class Address
3533
* {
3634
* // ...

src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Validator\Constraints;
1313

1414
/**
15-
* Annotation to define a group sequence provider.
15+
* Attribute to define a group sequence provider.
1616
*
1717
* @Annotation
1818
* @Target({"CLASS", "ANNOTATION"})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy