-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Deprecate ValidatorBuilder::enableAnnotationMapping()
and ValidatorBuilder::disableAnnotationMapping()
#51426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
8000By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ public function testAddMethodMappings() | |
*/ | ||
public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader() | ||
{ | ||
$this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); | ||
$this->assertSame($this->builder, $this->builder->enableAttributeMapping()); | ||
|
||
$this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::addDefaultDoctrineAnnotationReader()" is deprecated without replacement.'); | ||
$this->assertSame($this->builder, $this->builder->addDefaultDoctrineAnnotationReader()); | ||
|
@@ -102,7 +102,7 @@ public function testEnableAnnotationMappingWithCustomDoctrineAnnotationReader() | |
{ | ||
$reader = $this->createMock(Reader::class); | ||
|
||
$this->assertSame($this->builder, $this->builder->enableAnnotationMapping()); | ||
$this->assertSame($this->builder, $this->builder->enableAttributeMapping()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
|
||
$this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::setDoctrineAnnotationReader()" is deprecated without replacement.'); | ||
$this->assertSame($this->builder, $this->builder->setDoctrineAnnotationReader($reader)); | ||
|
@@ -116,9 +116,27 @@ 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->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->builder->disableAnnotationMapping(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not loose the assertion about the fluent API that we had before |
||
} | ||
|
||
public function testDisableAttributeMapping() | ||
{ | ||
$this->assertSame($this->builder, $this->builder->disableAnnotationMapping()); | ||
$this->assertSame($this->builder, $this->builder->disableAttributeMapping()); | ||
} | ||
|
||
public function testSetMappingCache() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,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,31 +187,56 @@ 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.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this exception message should be updated |
||
} | ||
|
||
$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__); | ||
|
||
$this->annotationReader = null; | ||
|
||
return $this->disableAttributeMapping(); | ||
} | ||
|
||
/** | ||
* Disables attribute based constraint mapping. | ||
* | ||
* @return $this | ||
*/ | ||
public function disableAttributeMapping(): static | ||
{ | ||
$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,7 +369,7 @@ public function getLoaders(): array | |
$loaders[] = new StaticMethodLoader($methodName); | ||
} | ||
|
||
if ($this->enableAnnotationMapping) { | ||
if ($this->enableAttributeMapping) { | ||
$loaders[] = new AnnotationLoader($this->annotationReader); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you don't rename the loader class as well, this work is incomplete |
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is really about annotation mapping. So I would rather expect both deprecations in it than changing method