8000 [Validator] Allow single integer for the `versions` option of the `Uu… · symfony/symfony@3f52000 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f52000

Browse files
[Validator] Allow single integer for the versions option of the Uuid constraint
1 parent 877a8e8 commit 3f52000

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

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+
6.4
5+
---
6+
7+
* Allow single integer for the `versions` option of the `Uuid` constraint
8+
49
6.3
510
---
611

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ class Uuid extends Constraint
100100
public $normalizer;
101101

102102
/**
103-
* @param int[]|null $versions
103+
* @param int[]|int|null $versions
104104
*/
105105
public function __construct(
106106
array $options = null,
107107
string $message = null,
108-
array $versions = null,
108+
array|int $versions = null,
109109
bool $strict = null,
110110
callable $normalizer = null,
111111
array $groups = null,
@@ -114,7 +114,7 @@ public function __construct(
114114
parent::__construct($options, $groups, $payload);
115115

116116
$this->message = $message ?? $this->message;
117-
$this->versions = $versions ?? $this->versions;
117+
$this->versions = (array) ($versions ?? $this->versions);
118118
$this->strict = $strict ?? $this->strict;
119119
$this->normalizer = $normalizer ?? $this->normalizer;
120120

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,13 @@ public static function getUuidForTimeBasedAssertions(): \Generator
296296
yield Uuid::V7_MONOTONIC => ['0184c292-b133-7e10-a3b4-d49c1ab49b2a', true];
297297
yield Uuid::V8_CUSTOM => ['00112233-4455-8677-8899-aabbccddeeff', false];
298298
}
299+
300+
public function testAcceptsSingleIntegerAsVersion()
301+
{
302+
$constraint = new Uuid(versions: 7);
303+
304+
$this->validator->validate('0184c292-b133-7e10-a3b4-d49c1ab49b2a', $constraint);
305+
306+
$this->assertNoViolation();
307+
}
299308
}

0 commit comments

Comments
 (0)
0