Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Validator] Remove deprecated code#41392

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.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletionsUPGRADE-6.0.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,7 +384,8 @@ Validator
After:

```php
$builder->enableAnnotationMapping(true)
$builder
->enableAnnotationMapping()
->setDoctrineAnnotationReader($reader);
```

Expand All@@ -399,7 +400,8 @@ Validator
After:

```php
$builder->enableAnnotationMapping(true)
$builder
->enableAnnotationMapping()
->addDefaultDoctrineAnnotationReader();
```

Expand Down
8 changes: 8 additions & 0 deletionssrc/Symfony/Component/Validator/CHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

6.0
---

* Remove the`allowEmptyString` option from the`Length` constraint
* Remove the`NumberConstraintTrait` trait
*`ValidatorBuilder::enableAnnotationMapping()` does not accept a Doctrine annotation reader anymore
*`ValidatorBuilder::enableAnnotationMapping()` won't automatically setup a Doctrine annotation reader anymore

5.3
---
* Add the`normalizer` option to the`Unique` constraint
Expand Down
5 changes: 0 additions & 5 deletionssrc/Symfony/Component/Validator/Constraints/Length.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,6 @@ class Length extends Constraint
public$min;
public$charset ='UTF-8';
public$normalizer;
public$allowEmptyString =false;

/**
* {@inheritdoc}
Expand DownExpand Up@@ -95,9 +94,5 @@ public function __construct(
if (null !==$this->normalizer && !\is_callable($this->normalizer)) {
thrownewInvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).',get_debug_type($this->normalizer)));
}

if (isset($options['allowEmptyString'])) {
trigger_deprecation('symfony/validator','5.2',sprintf('The "allowEmptyString" option of the "%s" constraint is deprecated.',self::class));
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedTypeException($constraint, Length::class);
}

if (null === $value || ('' === $value && $constraint->allowEmptyString)) {
if (null === $value) {
return;
}

Expand Down
View file
Open in desktop

This file was deleted.

10 changes: 2 additions & 8 deletionssrc/Symfony/Component/Validator/Constraints/Range.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -107,14 +107,8 @@ public function __construct(
throw new LogicException(sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "minPropertyPath" or "maxPropertyPath" option.', static::class));
}

if (null !== $this->min && null !== $this->max) {
$this->deprecatedMinMessageSet = isset($options['minMessage']) || null !== $minMessage;
$this->deprecatedMaxMessageSet = isset($options['maxMessage']) || null !== $maxMessage;

// BC layer, should throw a ConstraintDefinitionException in 6.0
if ($this->deprecatedMinMessageSet || $this->deprecatedMaxMessageSet) {
trigger_deprecation('symfony/validator', '4.4', '"minMessage" and "maxMessage" are deprecated when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
}
if (null !== $this->min && null !== $this->max && ($minMessage || $maxMessage)) {
throw new ConstraintDefinitionException(sprintf('The "%s" constraint can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.', static::class));
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,25 +22,12 @@
*/
class AddAutoMappingConfigurationPassimplements CompilerPassInterface
{
private$validatorBuilderService;
private$tag;

publicfunction__construct(string$validatorBuilderService ='validator.builder',string$tag ='validator.auto_mapper')
{
if (0 <\func_num_args()) {
trigger_deprecation('symfony/validator','5.3','Configuring "%s" is deprecated.',__CLASS__);
}

$this->validatorBuilderService =$validatorBuilderService;
$this->tag =$tag;
}

/**
* {@inheritdoc}
*/
publicfunctionprocess(ContainerBuilder$container)
{
if (!$container->hasParameter('validator.auto_mapping') || !$container->hasDefinition($this->validatorBuilderService)) {
if (!$container->hasParameter('validator.auto_mapping') || !$container->hasDefinition('validator.builder')) {
return;
}

Expand All@@ -60,8 +47,8 @@ public function process(ContainerBuilder $container)
}
}

$validatorBuilder =$container->getDefinition($this->validatorBuilderService);
foreach ($container->findTaggedServiceIds($this->tag)as$id =>$tags) {
$validatorBuilder =$container->getDefinition('validator.builder');
foreach ($container->findTaggedServiceIds('validator.auto_mapper')as$id =>$tags) {
$regexp =$this->getRegexp(array_merge($globalNamespaces,$servicesToNamespaces[$id] ?? []));
$validatorBuilder->addMethodCall('addLoader', [newReference($id)]);
$container->getDefinition($id)->setArgument('$classValidatorRegexp',$regexp);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,27 +22,14 @@
*/
class AddConstraintValidatorsPassimplements CompilerPassInterface
{
private$validatorFactoryServiceId;
private$constraintValidatorTag;

publicfunction__construct(string$validatorFactoryServiceId ='validator.validator_factory',string$constraintValidatorTag ='validator.constraint_validator')
{
if (0 <\func_num_args()) {
trigger_deprecation('symfony/validator','5.3','Configuring "%s" is deprecated.',__CLASS__);
}

$this->validatorFactoryServiceId =$validatorFactoryServiceId;
$this->constraintValidatorTag =$constraintValidatorTag;
}

publicfunctionprocess(ContainerBuilder$container)
{
if (!$container->hasDefinition($this->validatorFactoryServiceId)) {
if (!$container->hasDefinition('validator.validator_factory')) {
return;
}

$validators = [];
foreach ($container->findTaggedServiceIds($this->constraintValidatorTag,true)as$id =>$attributes) {
foreach ($container->findTaggedServiceIds('validator.constraint_validator',true)as$id =>$attributes) {
$definition =$container->getDefinition($id);

if (isset($attributes[0]['alias'])) {
Expand All@@ -53,7 +40,7 @@ public function process(ContainerBuilder $container)
}

$container
->getDefinition($this->validatorFactoryServiceId)
->getDefinition('validator.validator_factory')
->replaceArgument(0, ServiceLocatorTagPass::register($container,$validators))
;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,30 +21,17 @@
*/
class AddValidatorInitializersPassimplements CompilerPassInterface
{
private$builderService;
private$initializerTag;

publicfunction__construct(string$builderService ='validator.builder',string$initializerTag ='validator.initializer')
{
if (0 <\func_num_args()) {
trigger_deprecation('symfony/validator','5.3','Configuring "%s" is deprecated.',__CLASS__);
}

$this->builderService =$builderService;
$this->initializerTag =$initializerTag;
}

publicfunctionprocess(ContainerBuilder$container)
{
if (!$container->hasDefinition($this->builderService)) {
if (!$container->hasDefinition('validator.builder')) {
return;
}

$initializers = [];
foreach ($container->findTaggedServiceIds($this->initializerTag,true)as$id =>$attributes) {
foreach ($container->findTaggedServiceIds('validator.initializer',true)as$id =>$attributes) {
$initializers[] =newReference($id);
}

$container->getDefinition($this->builderService)->addMethodCall('addObjectInitializers', [$initializers]);
$container->getDefinition('validator.builder')->addMethodCall('addObjectInitializers', [$initializers]);
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,6 @@
namespaceSymfony\Component\Validator\Tests\Constraints;

usePHPUnit\Framework\TestCase;
useSymfony\Bridge\PhpUnit\ExpectDeprecationTrait;
useSymfony\Component\Validator\Constraints\Length;
useSymfony\Component\Validator\Exception\InvalidArgumentException;
useSymfony\Component\Validator\Mapping\ClassMetadata;
Expand All@@ -23,8 +22,6 @@
*/
class LengthTestextends TestCase
{
use ExpectDeprecationTrait;

publicfunctiontestNormalizerCanBeSet()
{
$length =newLength(['min' =>0,'max' =>10,'normalizer' =>'trim']);
Expand All@@ -46,25 +43,6 @@ public function testInvalidNormalizerObjectThrowsException()
newLength(['min' =>0,'max' =>10,'normalizer' =>new \stdClass()]);
}

/**
* @group legacy
* @dataProvider allowEmptyStringOptionData
*/
publicfunctiontestDeprecatedAllowEmptyStringOption(bool$value)
{
$this->expectDeprecation('Since symfony/validator 5.2: The "allowEmptyString" option of the "Symfony\Component\Validator\Constraints\Length" constraint is deprecated.');

newLength(['allowEmptyString' =>$value,'max' =>5]);
}

publicfunctionallowEmptyStringOptionData()
{
return [
[true],
[false],
];
}

publicfunctiontestConstraintDefaultOption()
{
$constraint =newLength(5);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,16 +30,6 @@ public function testNullIsValid()
$this->assertNoViolation();
}

/**
* @group legacy
*/
publicfunctiontestAllowEmptyString()
{
$this->validator->validate('',newLength(['value' =>6,'allowEmptyString' =>true]));

$this->assertNoViolation();
}

publicfunctiontestEmptyStringIsInvalid()
{
$this->validator->validate('',newLength([
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,15 +3,12 @@
namespaceSymfony\Component\Validator\Tests\Constraints;

usePHPUnit\Framework\TestCase;
useSymfony\Bridge\PhpUnit\ExpectDeprecationTrait;
useSymfony\Component\Validator\Constraints\Range;
useSymfony\Component\Validator\Exception\ConstraintDefinitionException;
useSymfony\Component\Validator\Exception\MissingOptionsException;

class RangeTestextends TestCase
{
use ExpectDeprecationTrait;

publicfunctiontestThrowsConstraintExceptionIfBothMinLimitAndPropertyPath()
{
$this->expectException(ConstraintDefinitionException::class);
Expand DownExpand Up@@ -59,43 +56,10 @@ public function testThrowsNoDefaultOptionConfiguredException()
newRange('value');
}

publicfunctionprovideDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet():array
{
return [
[['min' =>1,'max' =>10,'minMessage' =>'my_min_message'],true,false],
[['min' =>1,'max' =>10,'maxMessage' =>'my_max_message'],false,true],
[['min' =>1,'max' =>10,'minMessage' =>'my_min_message','maxMessage' =>'my_max_message'],true,true],
];
}

/**
* @group legacy
* @dataProvider provideDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet
*/
publicfunctiontestDeprecationTriggeredIfMinMaxAndMinMessageOrMaxMessageSet(array$options,bool$expectedDeprecatedMinMessageSet,bool$expectedDeprecatedMaxMessageSet)
{
$this->expectDeprecation('Since symfony/validator 4.4: "minMessage" and "maxMessage" are deprecated when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');

$sut =newRange($options);
$this->assertEquals($expectedDeprecatedMinMessageSet,$sut->deprecatedMinMessageSet);
$this->assertEquals($expectedDeprecatedMaxMessageSet,$sut->deprecatedMaxMessageSet);
}

publicfunctionprovideDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageNorMaxMessageSet():array
{
return [
[['min' =>1,'minMessage' =>'my_min_message','maxMessage' =>'my_max_message']],
[['max' =>10,'minMessage' =>'my_min_message','maxMessage' =>'my_max_message']],
[['min' =>1,'max' =>10,'notInRangeMessage' =>'my_message']],
];
}

/**
* @doesNotPerformAssertions
* @dataProvider provideDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageNorMaxMessageSet
*/
publicfunctiontestDeprecationNotTriggeredIfNotMinMaxOrNotMinMessageNorMaxMessageSet(array$options)
publicfunctiontestThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMinMessageOrMaxMessage()
{
newRange($options);
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
eval('new \Symfony\Component\Validator\Constraints\Range(min: "min", max: "max", minMessage: "minMessage", maxMessage: "maxMessage");');
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1037,8 +1037,8 @@ public function provideMessageIfMinAndMaxSet(): array
[
['minMessage' => 'min_message'],
0,
'min_message',
Range::TOO_LOW_ERROR,
$notInRangeMessage,
Range::NOT_IN_RANGE_ERROR,
],
[
['maxMessage' => 'max_message'],
Expand All@@ -1055,8 +1055,8 @@ public function provideMessageIfMinAndMaxSet(): array
[
['maxMessage' => 'max_message'],
15,
'max_message',
Range::TOO_HIGH_ERROR,
$notInRangeMessage,
Range::NOT_IN_RANGE_ERROR,
],
];
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ class ValidValidatorTest extends TestCase
publicfunctiontestPropertyPathsArePassedToNestedContexts()
{
$validatorBuilder =newValidatorBuilder();
$validator =$validatorBuilder->enableAnnotationMapping(true)->addDefaultDoctrineAnnotationReader()->getValidator();
$validator =$validatorBuilder->enableAnnotationMapping()->addDefaultDoctrineAnnotationReader()->getValidator();

$violations =$validator->validate(newFoo(),null, ['nested']);

Expand All@@ -23,7 +23,7 @@ public function testPropertyPathsArePassedToNestedContexts()
publicfunctiontestNullValues()
{
$validatorBuilder =newValidatorBuilder();
$validator =$validatorBuilder->enableAnnotationMapping(true)->addDefaultDoctrineAnnotationReader()->getValidator();
$validator =$validatorBuilder->enableAnnotationMapping()->addDefaultDoctrineAnnotationReader()->getValidator();

$foo =newFoo();
$foo->fooBar =null;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp