Skip to content

Commit f5b46e9

Browse files
bug symfony#59386 [Validator] fix named arguments support for the Slug constraint (xabbuh)
This PR was merged into the 7.3 branch. Discussion ---------- [Validator] fix named arguments support for the Slug constraint | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 23406c8 fix named arguments support for the Slug constraint
2 parents bbe1b6e + 23406c8 commit f5b46e9

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/Symfony/Component/Validator/Constraints/Slug.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Validator\Attribute\HasNamedArguments;
1415
use Symfony\Component\Validator\Constraint;
1516

1617
/**
@@ -26,14 +27,14 @@ class Slug extends Constraint
2627
public string $message = 'This value is not a valid slug.';
2728
public string $regex = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
2829

30+
#[HasNamedArguments]
2931
public function __construct(
30-
?array $options = null,
3132
?string $regex = null,
3233
?string $message = null,
3334
?array $groups = null,
3435
mixed $payload = null,
3536
) {
36-
parent::__construct($options, $groups, $payload);
37+
parent::__construct([], $groups, $payload);
3738

3839
$this->message = $message ?? $this->message;
3940
$this->regex = $regex ?? $this->regex;

src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public function testValidSlugs($slug)
6363
*/
6464
public function testInvalidSlugs($slug)
6565
{
66-
$constraint = new Slug([
67-
'message' => 'myMessage',
68-
]);
66+
$constraint = new Slug(message: 'myMessage');
6967

7068
$this->validator->validate($slug, $constraint);
7169

0 commit comments

Comments
 (0)