8000 minor #59613 [Validator] fix the version constaints not supporting na… · mathroc/symfony@99984e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99984e9

Browse files
committed
minor symfony#59613 [Validator] fix the version constaints not supporting named arguments are deprecated in (xabbuh)
This PR was merged into the 7.3 branch. Discussion ---------- [Validator] fix the version constaints not supporting named arguments are deprecated in | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 3eb621c fix the version constaints not supporting named arguments are deprecated in
2 parents d8b3cc6 + 3eb621c commit 99984e9

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

UPGRADE-7.3.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,37 @@ Serializer
4747
Validator
4848
---------
4949

50+
* Deprecate defining custom constraints not supporting named arguments
51+
52+
Before:
53+
54+
```php
55+
use Symfony\Component\Validator\Constraint;
56+
57+
class CustomConstraint extends Constraint
58+
{
59+
public function __construct(array $options)
60+
{
61+
// ...
62+
}
63+
}
64+
```
65+
66+
After:
67+
68+
```php
69+
use Symfony\Component\Validator\Attribute\HasNamedArguments;
70+
use Symfony\Component\Validator\Constraint;
71+
72+
class CustomConstraint extends Constraint
73+
{
74+
#[HasNamedArguments]
75+
public function __construct($option1, $option2, $groups, $payload)
76+
{
77+
// ...
78+
}
79+
}
80+
```
5081
* Deprecate passing an array of options to the constructors of the constraint classes, pass each option as a dedicated argument instead
5182

5283
Before:

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@ CHANGELOG
44
7.3
55
---
66

7+
* Deprecate defining custom constraints not supporting named arguments
8+
9+
Before:
10+
11+
```php
12+
use Symfony\Component\Validator\Constraint;
13+
14+
class CustomConstraint extends Constraint
15+
{
16+
public function __construct(array $options)
17+
{
18+
// ...
19+
}
20+
}
21+
```
22+
23+
After:
24+
25+
```php
26+
use Symfony\Component\Validator\Attribute\HasNamedArguments;
27+
use Symfony\Component\Validator\Constraint;
28+
29+
class CustomConstraint extends Constraint
30+
{
31+
#[HasNamedArguments]
32+
public function __construct($option1, $option2, $groups, $payload)
33+
{
34+
// ...
35+
}
36+
}
37+
```
738
* Deprecate passing an array of options to the constructors of the constraint classes, pass each option as a dedicated argument instead
839

940
Before:

src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected function newConstraint(string $name, mixed $options = null): Constrain
105105
}
106106

107107
if ($options) {
108-
trigger_deprecation('symfony/validator', '7.2', 'Using constraints not supporting named arguments is deprecated. Try adding the HasNamedArguments attribute to %s.', $className);
108+
trigger_deprecation('symfony/validator', '7.3', 'Using constraints not supporting named arguments is deprecated. Try adding the HasNamedArguments attribute to %s.', $className);
109109

110110
return new $className($options);
111111
}

src/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function testLoadConstraintWithoutNamedArgumentsSupport()
184184
$loader = new XmlFileLoader(__DIR__.'/constraint-without-named-arguments-support.xml');
185185
$metadata = new ClassMetadata(DummyEntityConstraintWithoutNamedArguments::class);
186186

187-
$this->expectUserDeprecationMessage('Since symfony/validator 7.2: Using constraints not supporting named arguments is deprecated. Try adding the HasNamedArguments attribute to Symfony\Component\Validator\Tests\Mapping\Loader\Fixtures\ConstraintWithoutNamedArguments.');
187+
$this->expectUserDeprecationMessage('Since symfony/validator 7.3: Using constraints not supporting named arguments is deprecated. Try adding the HasNamedArguments attribute to Symfony\Component\Validator\Tests\Mapping\Loader\Fixtures\ConstraintWithoutNamedArguments.');
188188

189189
$loader->loadClassMetadata($metadata);
190190
}

src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testLoadConstraintWithoutNamedArgumentsSupport()
200200
$loader = new YamlFileLoader(__DIR__.'/constraint-without-named-arguments-support.yml');
201201
$metadata = new ClassMetadata(DummyEntityConstraintWithoutNamedArguments::class);
202202

203-
$this->expectUserDeprecationMessage('Since symfony/validator 7.2: Using constraints not supporting named arguments is deprecated. Try adding the HasNamedArguments attribute to Symfony\Component\Validator\Tests\Mapping\Loader\Fixtures\ConstraintWithoutNamedArguments.');
203+
$this->expectUserDeprecationMessage('Since symfony/validator 7.3: Using constraints not supporting named arguments is deprecated. Try adding the HasNamedArguments attribute to Symfony\Component\Validator\Tests\Mapping\Loader\Fixtures\ConstraintWithoutNamedArguments.');
204204

205205
$loader->loadClassMetadata($metadata);
206206
}

0 commit comments

Comments
 (0)
0