diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index fc974c5a185a9..22e31fff2bb26 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.4 +--- + + * Allow single integer for the `versions` option of the `Uuid` constraint + 6.3 --- diff --git a/src/Symfony/Component/Validator/Constraints/Uuid.php b/src/Symfony/Component/Validator/Constraints/Uuid.php index 4c385d5322ca6..a96d2ceb936cb 100644 --- a/src/Symfony/Component/Validator/Constraints/Uuid.php +++ b/src/Symfony/Component/Validator/Constraints/Uuid.php @@ -100,12 +100,12 @@ class Uuid extends Constraint public $normalizer; /** - * @param int[]|null $versions + * @param int[]|int|null $versions */ public function __construct( array $options = null, string $message = null, - array $versions = null, + array|int $versions = null, bool $strict = null, callable $normalizer = null, array $groups = null, @@ -114,7 +114,7 @@ public function __construct( parent::__construct($options, $groups, $payload); $this->message = $message ?? $this->message; - $this->versions = $versions ?? $this->versions; + $this->versions = (array) ($versions ?? $this->versions); $this->strict = $strict ?? $this->strict; $this->normalizer = $normalizer ?? $this->normalizer; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php index c59faa96795c8..7c2e587cf6b89 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php @@ -296,4 +296,13 @@ public static function getUuidForTimeBasedAssertions(): \Generator yield Uuid::V7_MONOTONIC => ['0184c292-b133-7e10-a3b4-d49c1ab49b2a', true]; yield Uuid::V8_CUSTOM => ['00112233-4455-8677-8899-aabbccddeeff', false]; } + + public function testAcceptsSingleIntegerAsVersion() + { + $constraint = new Uuid(versions: 7); + + $this->validator->validate('0184c292-b133-7e10-a3b4-d49c1ab49b2a', $constraint); + + $this->assertNoViolation(); + } }