@@ -38,7 +38,7 @@ public function testGroupsAreNullByDefault()
public function testAttributes()
{
$metadata = new ClassMetaData(ValidDummy::class);
- $loader = new AnnotationLoader();
+ $loader = new AttributeLoader();
self::assertTrue($loader->loadClassMetadata($metadata));
[$bConstraint] = $metadata->properties['b']->getConstraints();
diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php
index 8c625949feb13..a3765172b1d8e 100644
--- a/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php
+++ b/src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php
@@ -20,7 +20,7 @@ class ValidValidatorTest extends TestCase
public function testPropertyPathsArePassedToNestedContexts()
{
$validatorBuilder = new ValidatorBuilder();
- $validator = $validatorBuilder->enableAnnotationMapping()->getValidator();
+ $validator = $validatorBuilder->enableAttributeMapping()->getValidator();
$violations = $validator->validate(new Foo(), null, ['nested']);
@@ -31,7 +31,7 @@ public function testPropertyPathsArePassedToNestedContexts()
public function testNullValues()
{
$validatorBuilder = new ValidatorBuilder();
- $validator = $validatorBuilder->enableAnnotationMapping()->getValidator();
+ $validator = $validatorBuilder->enableAttributeMapping()->getValidator();
$foo = new Foo();
$foo->fooBar = null;
diff --git a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php
index b3305b3c4fe86..8bf2a64cded0b 100644
--- a/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php
+++ b/src/Symfony/Component/Validator/Tests/Constraints/WhenTest.php
@@ -22,6 +22,7 @@
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;
final class WhenTest extends TestCase
@@ -130,7 +131,7 @@ public function testAnnotations()
public function testAttributes()
{
- $loader = new AnnotationLoader();
+ $loader = new AttributeLoader();
$metadata = new ClassMetadata(WhenTestWithAttributes::class);
self::assertTrue($loader->loadClassMetadata($metadata));
diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php
index 95cdee8c7dde0..d2f205d5177ac 100644
--- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php
+++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php
@@ -92,7 +92,7 @@ public function testLoadClassMetadata()
$propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}');
$validator = Validation::createValidatorBuilder()
- ->enableAnnotationMapping()
+ ->enableAttributeMapping()
->addLoader($propertyInfoLoader)
->getValidator()
;
@@ -230,7 +230,7 @@ public function testClassNoAutoMapping()
$propertyInfoLoader = new PropertyInfoLoader($propertyInfoStub, $propertyInfoStub, $propertyInfoStub, '{.*}');
$validator = Validation::createValidatorBuilder()
- ->enableAnnotationMapping()
+ ->enableAttributeMapping()
->addLoader($propertyInfoLoader)
->getValidator()
;
diff --git a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php
index 5d844031b3522..94b5c97da5441 100644
--- a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php
+++ b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php
@@ -81,6 +81,7 @@ public function testAddMethodMappings()
*/
public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader()
{
+ $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());
$this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::addDefaultDoctrineAnnotationReader()" is deprecated without replacement.');
@@ -102,6 +103,7 @@ public function testEnableAnnotationMappingWithCustomDoctrineAnnotationReader()
{
$reader = $this->createMock(Reader::class);
+ $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());
$this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::setDoctrineAnnotationReader()" is deprecated without replacement.');
@@ -116,11 +118,29 @@ public function testEnableAnnotationMappingWithCustomDoctrineAnnotationReader()
$this->assertSame($reader, $r->getValue($loaders[0]));
}
- public function testDisableAnnotationMapping()
+ /**
+ * @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());
+ }
+
public function testSetMappingCache()
{
$this->assertSame($this->builder, $this->builder->setMappingCache($this->createMock(CacheItemPoolInterface::class)));
diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php
index 88fd21645c180..0123056aeb608 100644
--- a/src/Symfony/Component/Validator/ValidatorBuilder.php
+++ b/src/Symfony/Component/Validator/ValidatorBuilder.php
@@ -22,6 +22,7 @@
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;
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
@@ -49,7 +50,7 @@ class ValidatorBuilder
private array $yamlMappings = [];
private array $methodMappings = [];
private ?Reader $annotationReader = null;
- private bool $enableAnnotationMapping = false;
+ private bool $enableAttributeMapping = false;
private ?MetadataFactoryInterface $metadataFactory = null;
private ConstraintValidatorFactoryInterface $validatorFactory;
private ?CacheItemPoolInterface $mappingCache = null;
@@ -187,30 +188,54 @@ public function addMethodMappings(array $methodNames): static
}
/**
- * Enables annotation and attribute based constraint mapping.
+ * @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.
+ *
+ * @return $this
+ */
+ public function enableAttributeMapping(): static
{
if (null !== $this->metadataFactory) {
- throw new ValidatorException('You cannot enable annotation mapping after setting a custom metadata factory. Configure your metadata factory instead.');
+ throw new ValidatorException('You cannot enable attribute mapping after setting a custom metadata factory. Configure your metadata factory instead.');
}
- $this->enableAnnotationMapping = true;
+ $this->enableAttributeMapping = true;
return $this;
}
/**
- * Disables annotation and attribute based constraint mapping.
+ * @deprecated since Symfony 6.4, use "disableAttributeMapping()" instead
*
* @return $this
*/
public function disableAnnotationMapping(): static
{
- $this->enableAnnotationMapping = false;
+ trigger_deprecation('symfony/validator', '6.4', 'Method "%s()" is deprecated, use "disableAttributeMapping()" instead.', __METHOD__);
+
+ return $this->disableAttributeMapping();
+ }
+
+ /**
+ * Disables attribute-based constraint mapping.
+ *
+ * @return $this
+ */
+ public function disableAttributeMapping(): static
+ {
$this->annotationReader = null;
+ $this->enableAttributeMapping = false;
return $this;
}
@@ -250,7 +275,7 @@ public function addDefaultDoctrineAnnotationReader(): static
*/
public function setMetadataFactory(MetadataFactoryInterface $metadataFactory): static
{
- if (\count($this->xmlMappings) > 0 || \count($this->yamlMappings) > 0 || \count($this->methodMappings) > 0 || $this->enableAnnotationMapping) {
+ if (\count($this->xmlMappings) > 0 || \count($this->yamlMappings) > 0 || \count($this->methodMappings) > 0 || $this->enableAttributeMapping) {
throw new ValidatorException('You cannot set a custom metadata factory after adding custom mappings. You should do either of both.');
}
@@ -344,8 +369,10 @@ public function getLoaders(): array
$loaders[] = new StaticMethodLoader($methodName);
}
- if ($this->enableAnnotationMapping) {
+ if ($this->enableAttributeMapping && $this->annotationReader) {
$loaders[] = new AnnotationLoader($this->annotationReader);
+ } elseif ($this->enableAttributeMapping) {
+ $loaders[] = new AttributeLoader();
}
return array_merge($loaders, $this->loaders);
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