Skip to content

Commit 3eb621c

Browse files
committed
fix the version constaints not supporting named arguments are deprecated in
1 parent c65ec65 commit 3eb621c

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
@@ -45,6 +45,37 @@ Serializer
4545
Validator
4646
---------
4747

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

5081
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)