From 6e8cab780ce502d9170fc867e75c377de9201022 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 22 Aug 2023 15:45:13 +0200 Subject: [PATCH] [FrameworkBundle][Validator] Remove remaining deprecations --- UPGRADE-7.0.md | 6 +- .../Bundle/FrameworkBundle/CHANGELOG.md | 2 + .../DependencyInjection/Configuration.php | 16 ---- .../Resources/config/schema/symfony-1.0.xsd | 2 - .../AbstractObjectNormalizerTest.php | 4 +- src/Symfony/Component/Validator/CHANGELOG.md | 3 + .../Validator/Constraints/Callback.php | 2 +- .../Component/Validator/Constraints/When.php | 3 - .../Mapping/Loader/AnnotationLoader.php | 96 ------------------- .../Mapping/Loader/AttributeLoader.php | 74 +++++++++++++- .../Validator/Tests/ConstraintTest.php | 2 +- .../Constraints/CallbackValidatorTest.php | 6 +- .../Constraints/CountValidatorTestCase.php | 2 +- .../Tests/Constraints/LengthTest.php | 2 +- .../Validator/Tests/Constraints/WhenTest.php | 1 - .../Mapping/Loader/AttributeLoaderTest.php | 21 ++-- .../Validator/Tests/ValidatorBuilderTest.php | 21 ---- .../Component/Validator/ValidatorBuilder.php | 25 ----- 18 files changed, 100 insertions(+), 188 deletions(-) delete mode 100644 src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php diff --git a/UPGRADE-7.0.md b/UPGRADE-7.0.md index 6d25459b18fe5..a0cb162e8c3d7 100644 --- a/UPGRADE-7.0.md +++ b/UPGRADE-7.0.md @@ -210,6 +210,8 @@ FrameworkBundle * Make the `framework.uid.default_uuid_version` config option default to `7` * Make the `framework.uid.time_based_uuid_version` config option default to `7` * Make the `framework.validation.email_validation_mode` config option default to `html5` + * Remove the `framework.validation.enable_annotations` config option, use `framework.validation.enable_attributes` instead + * Remove the `framework.serializer.enable_annotations` config option, use `framework.serializer.enable_attributes` instead HttpFoundation -------------- @@ -472,9 +474,11 @@ Validator * Remove `VALIDATION_MODE_LOOSE` from `Email` constraint, use `VALIDATION_MODE_HTML5` instead * Remove constraint `ExpressionLanguageSyntax`, use `ExpressionSyntax` instead * Remove Doctrine annotations support in favor of native attributes - * Remove the annotation reader parameter from the constructor signature of `AnnotationLoader` * Remove `ValidatorBuilder::setDoctrineAnnotationReader()` * Remove `ValidatorBuilder::addDefaultDoctrineAnnotationReader()` + * Remove `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead + * Remove `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead + * Remove `AnnotationLoader`, use `AttributeLoader` instead VarDumper --------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 00d71e31e6b6e..8117ffe6a7033 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -22,6 +22,8 @@ CHANGELOG * Make the `framework.uid.default_uuid_version` config option default to `7` * Make the `framework.uid.time_based_uuid_version` config option default to `7` * Make the `framework.validation.email_validation_mode` config option default to `html5` + * Remove the `framework.validation.enable_annotations` config option, use `framework.validation.enable_attributes` instead + * Remove the `framework.serializer.enable_annotations` config option, use `framework.serializer.enable_attributes` instead 6.4 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 72460206bac5d..a728efc2fcf3c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -989,7 +989,6 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e ->{$enableIfStandalone('symfony/validator', Validation::class)}() ->children() ->scalarNode('cache')->end() - ->booleanNode('enable_annotations')->end() ->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end() ->arrayNode('static_method') ->defaultValue(['loadValidatorMetadata']) @@ -1090,24 +1089,9 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e $rootNode ->children() ->arrayNode('serializer') - ->validate() - ->always(function ($v) { - if (isset($v['enable_annotations'])) { - trigger_deprecation('symfony/framework-bundle', '6.4', 'Option "enable_annotations" at "framework.serializer" is deprecated. Use the "enable_attributes" option instead.'); - - if (!isset($v['enable_attributes'])) { - $v['enable_attributes'] = $v['enable_annotations']; - } else { - 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.'); - } - } - - return $v; - })->end() ->info('serializer configuration') ->{$enableIfStandalone('symfony/serializer', Serializer::class)}() ->children() - ->booleanNode('enable_annotations')->end() ->booleanNode('enable_attributes')->{!class_exists(FullStack::class) ? 'defaultTrue' : 'defaultFalse'}()->end() ->scalarNode('name_converter')->end() ->scalarNode('circular_reference_handler')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 001b36d8ec44c..c3f2f967074e4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -266,7 +266,6 @@ - @@ -320,7 +319,6 @@ - diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index c845c17c5216f..1d70753f9b6cc 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -142,7 +142,7 @@ public function testDenormalizeWithNestedAttributesWithoutMetadata() public function testDenormalizeWithSnakeCaseNestedAttributes() { - $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $factory = new ClassMetadataFactory(new AnnotationLoader()); $normalizer = new ObjectNormalizer($factory, new CamelCaseToSnakeCaseNameConverter()); $data = [ 'one' => [ @@ -155,7 +155,7 @@ public function testDenormalizeWithSnakeCaseNestedAttributes() public function testNormalizeWithSnakeCaseNestedAttributes() { - $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $factory = new ClassMetadataFactory(new AnnotationLoader()); $normalizer = new ObjectNormalizer($factory, new CamelCaseToSnakeCaseNameConverter()); $dummy = new SnakeCaseNestedDummy(); $dummy->fooBar = 'fooBar'; diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index 17770d6540e51..e2b0747a8c6ba 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -15,6 +15,9 @@ CHANGELOG * Remove the annotation reader parameter from the constructor signature of `AnnotationLoader` * Remove `ValidatorBuilder::setDoctrineAnnotationReader()` * Remove `ValidatorBuilder::addDefaultDoctrineAnnotationReader()` + * Remove `ValidatorBuilder::enableAnnotationMapping()`, use `ValidatorBuilder::enableAttributeMapping()` instead + * Remove `ValidatorBuilder::disableAnnotationMapping()`, use `ValidatorBuilder::disableAttributeMapping()` instead + * Remove `AnnotationLoader`, use `AttributeLoader` instead 6.4 --- diff --git a/src/Symfony/Component/Validator/Constraints/Callback.php b/src/Symfony/Component/Validator/Constraints/Callback.php index 2f0defe2cf426..c4bf70ea93b74 100644 --- a/src/Symfony/Component/Validator/Constraints/Callback.php +++ b/src/Symfony/Component/Validator/Constraints/Callback.php @@ -26,7 +26,7 @@ class Callback extends Constraint public function __construct(array|string|callable $callback = null, array $groups = null, mixed $payload = null, array $options = []) { - // Invocation through annotations with an array parameter only + // Invocation through attributes with an array parameter only if (\is_array($callback) && 1 === \count($callback) && isset($callback['value'])) { $callback = $callback['value']; } diff --git a/src/Symfony/Component/Validator/Constraints/When.php b/src/Symfony/Component/Validator/Constraints/When.php index 5dc9a8ed159bc..807410d8166d5 100644 --- a/src/Symfony/Component/Validator/Constraints/When.php +++ b/src/Symfony/Component/Validator/Constraints/When.php @@ -16,9 +16,6 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Exception\LogicException; -/** - * @Target({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"}) - */ #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class When extends Composite { diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php deleted file mode 100644 index 1db0c5e6be43b..0000000000000 --- a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php +++ /dev/null @@ -1,96 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Mapping\Loader; - -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Constraints\Callback; -use Symfony\Component\Validator\Constraints\GroupSequence; -use Symfony\Component\Validator\Constraints\GroupSequenceProvider; -use Symfony\Component\Validator\Exception\MappingException; -use Symfony\Component\Validator\Mapping\ClassMetadata; - -/** - * Loads validation metadata using PHP attributes. - * - * @deprecated since Symfony 6.4, use {@see AttributeLoader} instead - * - * @author Bernhard Schussek - * @author Alexander M. Turek - */ -class AnnotationLoader implements LoaderInterface -{ - public function loadClassMetadata(ClassMetadata $metadata): bool - { - $reflClass = $metadata->getReflectionClass(); - $className = $reflClass->name; - $success = false; - - foreach ($this->getAnnotations($reflClass) as $constraint) { - if ($constraint instanceof GroupSequence) { - $metadata->setGroupSequence($constraint->groups); - } elseif ($constraint instanceof GroupSequenceProvider) { - $metadata->setGroupSequenceProvider(true); - } elseif ($constraint instanceof Constraint) { - $metadata->addConstraint($constraint); - } - - $success = true; - } - - foreach ($reflClass->getProperties() as $property) { - if ($property->getDeclaringClass()->name === $className) { - foreach ($this->getAnnotations($property) as $constraint) { - if ($constraint instanceof Constraint) { - $metadata->addPropertyConstraint($property->name, $constraint); - } - - $success = true; - } - } - } - - foreach ($reflClass->getMethods() as $method) { - if ($method->getDeclaringClass()->name === $className) { - foreach ($this->getAnnotations($method) as $constraint) { - if ($constraint instanceof Callback) { - $constraint->callback = $method->getName(); - - $metadata->addConstraint($constraint); - } elseif ($constraint instanceof Constraint) { - if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) { - $metadata->addGetterMethodConstraint(lcfirst($matches[2]), $matches[0], $constraint); - } else { - throw new MappingException(sprintf('The constraint on "%s::%s()" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name)); - } - } - - $success = true; - } - } - } - - return $success; - } - - private function getAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionProperty $reflection): iterable - { - foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) { - yield $attribute->newInstance(); - } - foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) { - yield $attribute->newInstance(); - } - foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { - yield $attribute->newInstance(); - } - } -} diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php index 2a8a75e1e60b8..9674122b64115 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/AttributeLoader.php @@ -11,6 +11,13 @@ namespace Symfony\Component\Validator\Mapping\Loader; +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Constraints\Callback; +use Symfony\Component\Validator\Constraints\GroupSequence; +use Symfony\Component\Validator\Constraints\GroupSequenceProvider; +use Symfony\Component\Validator\Exception\MappingException; +use Symfony\Component\Validator\Mapping\ClassMetadata; + /** * Loads validation metadata using PHP attributes. * @@ -18,10 +25,71 @@ * @author Alexander M. Turek * @author Alexandre Daubois */ -class AttributeLoader extends AnnotationLoader +class AttributeLoader implements LoaderInterface { - public function __construct() + public function loadClassMetadata(ClassMetadata $metadata): bool + { + $reflClass = $metadata->getReflectionClass(); + $className = $reflClass->name; + $success = false; + + foreach ($this->getAttributes($reflClass) as $constraint) { + if ($constraint instanceof GroupSequence) { + $metadata->setGroupSequence($constraint->groups); + } elseif ($constraint instanceof GroupSequenceProvider) { + $metadata->setGroupSequenceProvider(true); + } elseif ($constraint instanceof Constraint) { + $metadata->addConstraint($constraint); + } + + $success = true; + } + + foreach ($reflClass->getProperties() as $property) { + if ($property->getDeclaringClass()->name === $className) { + foreach ($this->getAttributes($property) as $constraint) { + if ($constraint instanceof Constraint) { + $metadata->addPropertyConstraint($property->name, $constraint); + } + + $success = true; + } + } + } + + foreach ($reflClass->getMethods() as $method) { + if ($method->getDeclaringClass()->name === $className) { + foreach ($this->getAttributes($method) as $constraint) { + if ($constraint instanceof Callback) { + $constraint->callback = $method->getName(); + + $metadata->addConstraint($constraint); + } elseif ($constraint instanceof Constraint) { + if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) { + $metadata->addGetterMethodConstraint(lcfirst($matches[2]), $matches[0], $constraint); + } else { + throw new MappingException(sprintf('The constraint on "%s::%s()" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name)); + } + } + + $success = true; + } + } + } + + return $success; + } + + private function getAttributes(\ReflectionMethod|\ReflectionClass|\ReflectionProperty $reflection): iterable { - parent::__construct(null); + foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) { + yield $attribute->newInstance(); + } + foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) { + yield $attribute->newInstance(); + } + foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { + yield $attribute->newInstance(); + } } } diff --git a/src/Symfony/Component/Validator/Tests/ConstraintTest.php b/src/Symfony/Component/Validator/Tests/ConstraintTest.php index 3d233c17815b7..80e33c7b722a8 100644 --- a/src/Symfony/Component/Validator/Tests/ConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/ConstraintTest.php @@ -245,7 +245,7 @@ public function testOptionsWithInvalidInternalPointer() $this->assertEquals('foo', $constraint->property1); } - public function testAnnotationSetUndefinedDefaultOption() + public function testAttributeSetUndefinedDefaultOption() { $this->expectException(ConstraintDefinitionException::class); $this->expectExceptionMessage('No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".'); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php index 084b192b64371..e888baa7a6596 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -205,7 +205,7 @@ public function testConstraintGetTargets() $this->assertEquals($targets, $constraint->getTargets()); } - // Should succeed. Needed when defining constraints as annotations. + // Should succeed. Needed when defining constraints as attributes. public function testNoConstructorArguments() { $constraint = new Callback(); @@ -213,14 +213,14 @@ public function testNoConstructorArguments() $this->assertSame([Constraint::CLASS_CONSTRAINT, Constraint::PROPERTY_CONSTRAINT], $constraint->getTargets()); } - public function testAnnotationInvocationSingleValued() + public function testAttributeInvocationSingleValued() { $constraint = new Callback(['value' => 'validateStatic']); $this->assertEquals(new Callback('validateStatic'), $constraint); } - public function testAnnotationInvocationMultiValued() + public function testAttributeInvocationMultiValued() { $constraint = new Callback(['value' => [__CLASS__.'_Class', 'validateCallback']]); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTestCase.php index 104c90773264e..c52cd4e69d394 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTestCase.php @@ -283,7 +283,7 @@ public function testDefaultOption() $this->assertEquals(5, $constraint->max); } - public function testConstraintAnnotationDefaultOption() + public function testConstraintAttributeDefaultOption() { $constraint = new Count(['value' => 5, 'exactMessage' => 'message']); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php index 793491fc29b4f..03bd37674922e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php @@ -70,7 +70,7 @@ public function testConstraintDefaultOption() self::assertEquals(5, $constraint->max); } - public function testConstraintAnnotationDefaultOption() + public function testConstraintAttributeDefaultOption() { $constraint = new Length(['value' => 5, 'exactMessage' => 'message']); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php index 03a856c6ac436..12d2bd146dda1 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php @@ -19,7 +19,6 @@ use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Exception\MissingOptionsException; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Tests\Constraints\Fixtures\WhenTestWithAttributes; diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php index c8975dbd29383..f9cb0da9b2d3c 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/AttributeLoaderTest.php @@ -29,7 +29,6 @@ use Symfony\Component\Validator\Constraints\Type; use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; @@ -37,7 +36,7 @@ class AttributeLoaderTest extends TestCase { public function testLoadClassMetadataReturnsTrueIfSuccessful() { - $loader = $this->createAnnotationLoader(); + $loader = $this->createAttributeLoader(); $metadata = new ClassMetadata($this->getFixtureNamespace().'\Entity'); $this->assertTrue($loader->loadClassMetadata($metadata)); @@ -45,7 +44,7 @@ public function testLoadClassMetadataReturnsTrueIfSuccessful() public function testLoadClassMetadataReturnsFalseIfNotSuccessful() { - $loader = $this->createAnnotationLoader(); + $loader = $this->createAttributeLoader(); $metadata = new ClassMetadata('\stdClass'); $this->assertFalse($loader->loadClassMetadata($metadata)); @@ -53,7 +52,7 @@ public function testLoadClassMetadataReturnsFalseIfNotSuccessful() public function testLoadClassMetadata() { - $loader = $this->createAnnotationLoader(); + $loader = $this->createAttributeLoader(); $namespace = $this->getFixtureNamespace(); $metadata = new ClassMetadata($namespace.'\Entity'); @@ -105,11 +104,11 @@ public function testLoadClassMetadata() } /** - * Test MetaData merge with parent annotation. + * Test MetaData merge with parent attribute. */ public function testLoadParentClassMetadata() { - $loader = $this->createAnnotationLoader(); + $loader = $this->createAttributeLoader(); $namespace = $this->getFixtureNamespace(); // Load Parent MetaData @@ -124,11 +123,11 @@ public function testLoadParentClassMetadata() } /** - * Test MetaData merge with parent annotation. + * Test MetaData merge with parent attribute. */ public function testLoadClassMetadataAndMerge() { - $loader = $this->createAnnotationLoader(); + $loader = $this->createAttributeLoader(); $namespace = $this->getFixtureNamespace(); // Load Parent MetaData @@ -196,9 +195,9 @@ public function testLoadClassMetadataAndMerge() $this->assertInstanceOf(NotNull::class, $otherMetadata[1]->getConstraints()[0]); } - public function testLoadGroupSequenceProviderAnnotation() + public function testLoadGroupSequenceProviderAttribute() { - $loader = $this->createAnnotationLoader(); + $loader = $this->createAttributeLoader(); $namespace = $this->getFixtureNamespace(); $metadata = new ClassMetadata($namespace.'\GroupSequenceProviderEntity'); @@ -211,7 +210,7 @@ public function testLoadGroupSequenceProviderAnnotation() $this->assertEquals($expected, $metadata); } - protected function createAnnotationLoader(): AnnotationLoader + protected function createAttributeLoader(): AttributeLoader { return new AttributeLoader(); } diff --git a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php index f2253697cdd88..c57a507e25579 100644 --- a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php +++ b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\Validator\RecursiveValidator; @@ -22,8 +21,6 @@ class ValidatorBuilderTest extends TestCase { - use ExpectDeprecationTrait; - private ValidatorBuilder $builder; protected function setUp(): void @@ -73,24 +70,6 @@ public function testAddMethodMappings() $this->assertSame($this->builder, $this->builder->addMethodMappings([])); } - /** - * @group legacy - */ - public function testExpectDeprecationWhenEnablingAnnotationMapping() - { - $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead.'); - $this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); - } - - /** - * @group legacy - */ - public function testExpectDeprecationWhenDisablingAnnotationMapping() - { - $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::disableAnnotationMapping()" is deprecated, use "disableAttributeMapping()" instead.'); - $this->assertSame($this->builder, $this->builder->disableAnnotationMapping()); - } - public function testDisableAttributeMapping() { $this->assertSame($this->builder, $this->builder->disableAttributeMapping()); diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index ec7e6e77bc7ee..44f7161fac1e3 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -16,7 +16,6 @@ use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; -use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Symfony\Component\Validator\Mapping\Loader\LoaderChain; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; @@ -181,18 +180,6 @@ public function addMethodMappings(array $methodNames): static return $this; } - /** - * @deprecated since Symfony 6.4, use "enableAttributeMapping()" instead. - * - * @return $this - */ - public function enableAnnotationMapping(): static - { - trigger_deprecation('symfony/validator', '6.4', 'Method "%s()" is deprecated, use "enableAttributeMapping()" instead.', __METHOD__); - - return $this->enableAttributeMapping(); - } - /** * Enables attribute-based constraint mapping. * @@ -209,18 +196,6 @@ public function enableAttributeMapping(): static return $this; } - /** - * @deprecated since Symfony 6.4, use "disableAttributeMapping()" instead - * - * @return $this - */ - public function disableAnnotationMapping(): static - { - trigger_deprecation('symfony/validator', '6.4', 'Method "%s()" is deprecated, use "disableAttributeMapping()" instead.', __METHOD__); - - return $this->disableAttributeMapping(); - } - /** * Disables attribute-based constraint mapping. *