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

Skip to content

Commit 7e4a84d

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

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

UPGRADE-7.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ release process, both versions will have the same features, but Symfony 7.0 won'
66
To upgrade, make sure to resolve all deprecation notices.
77

88
This file will be updated on the branch 7.0 for each deprecated feature that is removed.
9+
10+
Validator
11+
---------
12+
13+
* Changed `$versions` parameter type of the `Uuid::__construct()` method from `array` to `array|int`.

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+
7.0
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