Skip to content

Commit 842e8f2

Browse files
[FrameworkBundle][Validator] Deprecate annotation occurrences
1 parent 169bfc8 commit 842e8f2

Some content is hidden

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

64 files changed

+211
-131
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ CHANGELOG
1212
* Deprecate `ValidatorBuilder::addDefaultDoctrineAnnotationReader()`
1313
* Add `number`, `finite-number` and `finite-float` types to `Type` constraint
1414
* Add the `withSeconds` option to the `Time` constraint that allows to pass time without seconds
15+
* Deprecate `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead
16+
* Deprecate `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead
17+
* Deprecate `AnnotationLoader`, use `AttributeLoader` instead
1518

1619
6.3
1720
---

Mapping/Loader/AnnotationLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
/**
2323
* Loads validation metadata using a Doctrine annotation {@link Reader} or using PHP 8 attributes.
2424
*
25+
* @deprecated since Symfony 6.4, use {@see AttributeLoader} instead
26+
*
2527
* @author Bernhard Schussek <[email protected]>
2628
* @author Alexander M. Turek <[email protected]>
2729
*/

Mapping/Loader/AttributeLoader.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Mapping\Loader;
13+
14+
/**
15+
* Loads validation metadata using PHP attributes.
16+
*
17+
* @author Bernhard Schussek <[email protected]>
18+
* @author Alexander M. Turek <[email protected]>
19+
* @author Alexandre Daubois <[email protected]>
20+
*/
21+
class AttributeLoader extends AnnotationLoader
22+
{
23+
public function __construct()
24+
{
25+
parent::__construct(null);
26+
}
27+
}

Tests/Command/DebugCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Validator\Command\DebugCommand;
1717
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
1818
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
19-
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
19+
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
2020
use Symfony\Component\Validator\Tests\Dummy\DummyClassOne;
2121

2222
/**
@@ -26,7 +26,7 @@ class DebugCommandTest extends TestCase
2626
{
2727
public function testOutputWithClassArgument()
2828
{
29-
$command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader()));
29+
$command = new DebugCommand(new LazyLoadingMetadataFactory(new AttributeLoader()));
3030

3131
$tester = new CommandTester($command);
3232
$tester->execute(['class' => DummyClassOne::class], ['decorated' => false]);
@@ -82,7 +82,7 @@ public function testOutputWithClassArgument()
8282

8383
public function testOutputWithPathArgument()
8484
{
85-
$command = new DebugCommand(new LazyLoadingMetadataFactory(new AnnotationLoader()));
85+
$command = new DebugCommand(new LazyLoadingMetadataFactory(new AttributeLoader()));
8686

8787
$tester = new CommandTester($command);
8888
$tester->execute(['class' => __DIR__.'/../Dummy'], ['decorated' => false]);

Tests/Constraints/BicValidatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1717
use Symfony\Component\Validator\Exception\UnexpectedValueException;
1818
use Symfony\Component\Validator\Mapping\ClassMetadata;
19-
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
19+
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
2020
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
2121

2222
class BicValidatorTest extends ConstraintValidatorTestCase
@@ -74,7 +74,7 @@ public function testInvalidComparisonToPropertyPath()
7474
public function testInvalidComparisonToPropertyPathFromAttribute()
7575
{
7676
$classMetadata = new ClassMetadata(BicDummy::class);
77-
(new AnnotationLoader())->loadClassMetadata($classMetadata);
77+
(new AttributeLoader())->loadClassMetadata($classMetadata);
7878

7979
[$constraint] = $classMetadata->properties['bic1']->constraints;
8080

@@ -116,7 +116,7 @@ public function testInvalidComparisonToValue()
116116
public function testInvalidComparisonToValueFromAttribute()
117117
{
118118
$classMetadata = new ClassMetadata(BicDummy::class);
119-
(new AnnotationLoader())->loadClassMetadata($classMetadata);
119+
(new AttributeLoader())->loadClassMetadata($classMetadata);
120120

121121
[$constraint] = $classMetadata->properties['bic1']->constraints;
122122

Tests/Constraints/CardSchemeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraints\CardScheme;
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 CardSchemeTest extends TestCase
2020
{
2121
public function testAttributes()
2222
{
2323
$metadata = new ClassMetadata(CardSchemeDummy::class);
24-
$loader = new AnnotationLoader();
24+
$loader = new AttributeLoader();
2525
self::assertTrue($loader->loadClassMetadata($metadata));
2626

2727
[$aConstraint] = $metadata->properties['a']->getConstraints();

Tests/Constraints/CascadeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Symfony\Component\Validator\Constraints\Cascade;
1616
use Symfony\Component\Validator\Mapping\CascadingStrategy;
1717
use Symfony\Component\Validator\Mapping\ClassMetadata;
18-
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
18+
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
1919

2020
class CascadeTest extends TestCase
2121
{
2222
public function testCascadeAttribute()
2323
{
2424
$metadata = new ClassMetadata(CascadeDummy::class);
25-
$loader = new AnnotationLoader();
25+
$loader = new AttributeLoader();
2626
self::assertSame(CascadingStrategy::NONE, $metadata->getCascadingStrategy());
2727
self::assertTrue($loader->loadClassMetadata($metadata));
2828
self::assertSame(CascadingStrategy::CASCADE, $metadata->getCascadingStrategy());

Tests/Constraints/ChoiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraints\Choice;
1616
use Symfony\Component\Validator\Mapping\ClassMetadata;
17-
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
17+
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
1818
use Symfony\Component\Validator\Tests\Fixtures\ConstraintChoiceWithPreset;
1919

2020
class ChoiceTest extends TestCase
@@ -29,7 +29,7 @@ public function testSetDefaultPropertyChoice()
2929
public function testAttributes()
3030
{
3131
$metadata = new ClassMetadata(ChoiceDummy::class);
32-
$loader = new AnnotationLoader();
32+
$loader = new AttributeLoader();
3333
self::assertTrue($loader->loadClassMetadata($metadata));
3434

3535
/** @var Choice $aConstraint */

Tests/Constraints/CidrTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Validator\Constraints\Ip;
1717
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1818
use Symfony\Component\Validator\Mapping\ClassMetadata;
19-
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
19+
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
2020

2121
class CidrTest extends TestCase
2222
{
@@ -123,7 +123,7 @@ public static function getValidMinMaxValues(): array
123123
public function testAttributes()
124124
{
125125
$metadata = new ClassMetadata(CidrDummy::class);
126-
$loader = new AnnotationLoader();
126+
$loader = new AttributeLoader();
127127
self::assertTrue($loader->loadClassMetadata($metadata));
128128

129129
[$aConstraint] = $metadata->properties['a']->getConstraints();

Tests/Constraints/CountTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraints\Count;
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 CountTest extends TestCase
2020
{
2121
public function testAttributes()
2222
{
2323
$metadata = new ClassMetadata(CountDummy::class);
24-
$loader = new AnnotationLoader();
24+
$loader = new AttributeLoader();
2525
self::assertTrue($loader->loadClassMetadata($metadata));
2626

2727
[$aConstraint] = $metadata->properties['a']->getConstraints();

0 commit comments

Comments
 (0)