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

Commitfbbde1e

Browse files
committed
deprecate the "allowEmptyString" option
1 parent7950851 commitfbbde1e

File tree

12 files changed

+56
-16
lines changed

12 files changed

+56
-16
lines changed

‎UPGRADE-5.2.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
UPGRADE FROM 5.1 to 5.2
2+
=======================
3+
4+
Validator
5+
---------
6+
7+
* Deprecated the`allowEmptyString` option of the`Length` constraint.

‎UPGRADE-6.0.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Security
115115
* Removed`DefaultLogoutSuccessHandler` in favor of`DefaultLogoutListener`.
116116
* Added a`logout(Request $request, Response $response, TokenInterface $token)` method to the`RememberMeServicesInterface`.
117117

118+
Validator
119+
---------
120+
121+
* Removed the`allowEmptyString` option from the`Length` constraint.
122+
118123
Yaml
119124
----
120125

‎src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoctrineLoaderEntity.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class DoctrineLoaderEntity extends DoctrineLoaderParentEntity
3636

3737
/**
3838
* @ORM\Column(length=20)
39-
* @Assert\Length(min=5, allowEmptyString=true)
39+
* @Assert\Length(min=5)
4040
*/
4141
public$mergedMaxLength;
4242

4343
/**
4444
* @ORM\Column(length=20)
45-
* @Assert\Length(min=1, max=10, allowEmptyString=true)
45+
* @Assert\Length(min=1, max=10)
4646
*/
4747
public$alreadyMappedMaxLength;
4848

‎src/Symfony/Bridge/Doctrine/Tests/Resources/validator/BaseUser.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<optionname="min">2</option>
1414
<optionname="max">120</option>
1515
<optionname="groups">Registration</option>
16-
<optionname="allowEmptyString">true</option>
1716
</constraint>
1817
</property>
1918
</class>

‎src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testGroupSequenceWithConstraintsOption()
6767
->create(FormTypeTest::TESTED_TYPE,null, (['validation_groups' =>newGroupSequence(['First','Second'])]))
6868
->add('field', TextTypeTest::TESTED_TYPE, [
6969
'constraints' => [
70-
newLength(['min' =>10,'allowEmptyString' =>true,'groups' => ['First']]),
70+
newLength(['min' =>10,'groups' => ['First']]),
7171
newNotBlank(['groups' => ['Second']]),
7272
],
7373
])
@@ -83,8 +83,6 @@ public function testGroupSequenceWithConstraintsOption()
8383

8484
publicfunctiontestManyFieldsGroupSequenceWithConstraintsOption()
8585
{
86-
$allowEmptyString =property_exists(Length::class,'allowEmptyString') ? ['allowEmptyString' =>true] : [];
87-
8886
$formMetadata =newClassMetadata(Form::class);
8987
$authorMetadata = (newClassMetadata(Author::class))
9088
->addPropertyConstraint('firstName',newNotBlank(['groups' =>'Second']))
@@ -116,7 +114,7 @@ public function testManyFieldsGroupSequenceWithConstraintsOption()
116114
->add('firstName', TextTypeTest::TESTED_TYPE)
117115
->add('lastName', TextTypeTest::TESTED_TYPE, [
118116
'constraints' => [
119-
newLength(['min' =>10,'groups' => ['First']] +$allowEmptyString),
117+
newLength(['min' =>10,'groups' => ['First']]),
120118
],
121119
])
122120
->add('australian', TextTypeTest::TESTED_TYPE, [

‎src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ public function testFieldConstraintsInvalidateFormIfFieldIsSubmitted()
9494

9595
publicfunctiontestFieldsValidateInSequence()
9696
{
97-
$allowEmptyString =property_exists(Length::class,'allowEmptyString') ? ['allowEmptyString' =>true] : [];
98-
9997
$form =$this->createForm(FormType::class,null, [
10098
'validation_groups' =>newGroupSequence(['group1','group2']),
10199
])
102100
->add('foo', TextType::class, [
103-
'constraints' => [newLength(['min' =>10,'groups' => ['group1']] +$allowEmptyString)],
101+
'constraints' => [newLength(['min' =>10,'groups' => ['group1']])],
104102
])
105103
->add('bar', TextType::class, [
106104
'constraints' => [newNotBlank(['groups' => ['group2']])],
@@ -117,16 +115,14 @@ public function testFieldsValidateInSequence()
117115

118116
publicfunctiontestFieldsValidateInSequenceWithNestedGroupsArray()
119117
{
120-
$allowEmptyString =property_exists(Length::class,'allowEmptyString') ? ['allowEmptyString' =>true] : [];
121-
122118
$form =$this->createForm(FormType::class,null, [
123119
'validation_groups' =>newGroupSequence([['group1','group2'],'group3']),
124120
])
125121
->add('foo', TextType::class, [
126-
'constraints' => [newLength(['min' =>10,'groups' => ['group1']] +$allowEmptyString)],
122+
'constraints' => [newLength(['min' =>10,'groups' => ['group1']])],
127123
])
128124
->add('bar', TextType::class, [
129-
'constraints' => [newLength(['min' =>10,'groups' => ['group2']] +$allowEmptyString)],
125+
'constraints' => [newLength(['min' =>10,'groups' => ['group2']])],
130126
])
131127
->add('baz', TextType::class, [
132128
'constraints' => [newNotBlank(['groups' => ['group3']])],

‎src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorTypeGuesserTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function guessRequiredProvider()
6666
[newNotNull(),newValueGuess(true, Guess::HIGH_CONFIDENCE)],
6767
[newNotBlank(),newValueGuess(true, Guess::HIGH_CONFIDENCE)],
6868
[newIsTrue(),newValueGuess(true, Guess::HIGH_CONFIDENCE)],
69-
[newLength(['min' =>10,'max' =>10,'allowEmptyString' =>true]),newValueGuess(false, Guess::LOW_CONFIDENCE)],
69+
[newLength(['min' =>10,'max' =>10]),newValueGuess(false, Guess::LOW_CONFIDENCE)],
7070
[newRange(['min' =>1,'max' =>20]),newValueGuess(false, Guess::LOW_CONFIDENCE)],
7171
];
7272
}
@@ -102,7 +102,7 @@ public function testGuessMaxLengthForConstraintWithMaxValue()
102102

103103
publicfunctiontestGuessMaxLengthForConstraintWithMinValue()
104104
{
105-
$constraint =newLength(['min' =>'2','allowEmptyString' =>true]);
105+
$constraint =newLength(['min' =>'2']);
106106

107107
$result =$this->guesser->guessMaxLengthForConstraint($constraint);
108108
$this->assertNull($result);

‎src/Symfony/Component/Validator/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.2.0
5+
-----
6+
7+
* deprecated the`allowEmptyString` option of the`Length` constraint
8+
49
5.1.0
510
-----
611

‎src/Symfony/Component/Validator/Constraints/Length.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,9 @@ public function __construct($options = null)
6464
if (null !==$this->normalizer && !\is_callable($this->normalizer)) {
6565
thrownewInvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).',get_debug_type($this->normalizer)));
6666
}
67+
68+
if (isset($options['allowEmptyString'])) {
69+
trigger_deprecation('symfony/validator','5.2',sprintf('The "allowEmptyString" option of the "%s" constraint is deprecated.',self::class));
70+
}
6771
}
6872
}

‎src/Symfony/Component/Validator/Tests/Constraints/LengthTest.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
namespaceSymfony\Component\Validator\Tests\Constraints;
1313

1414
usePHPUnit\Framework\TestCase;
15+
useSymfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
useSymfony\Component\Validator\Constraints\Length;
1617

1718
/**
1819
* @author Renan Taranto <renantaranto@gmail.com>
1920
*/
2021
class LengthTestextends TestCase
2122
{
23+
use ExpectDeprecationTrait;
24+
2225
publicfunctiontestNormalizerCanBeSet()
2326
{
2427
$length =newLength(['min' =>0,'max' =>10,'normalizer' =>'trim']);
@@ -39,4 +42,23 @@ public function testInvalidNormalizerObjectThrowsException()
3942
$this->expectExceptionMessage('The "normalizer" option must be a valid callable ("stdClass" given).');
4043
newLength(['min' =>0,'max' =>10,'normalizer' =>new \stdClass()]);
4144
}
45+
46+
/**
47+
* @group legacy
48+
* @dataProvider allowEmptyStringOptionData
49+
*/
50+
publicfunctiontestDoNotAllowEmptyStringWithoutMinLength(bool$value)
51+
{
52+
$this->expectDeprecation('Since symfony/validator 5.2: The "allowEmptyString" option of the "Symfony\Component\Validator\Constraints\Length" constraint is deprecated.');
53+
54+
newLength(['allowEmptyString' =>$value,'max' =>5]);
55+
}
56+
57+
publicfunctionallowEmptyStringOptionData()
58+
{
59+
return [
60+
[true],
61+
[false],
62+
];
63+
}
4264
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp