feature #38332 [Validator] Add support for UUIDv6 in Uuid constraint (nicolas-grekas)
This PR was merged into the 5.2-dev branch.
Discussion
----------
[Validator] Add support for UUIDv6 in Uuid constraint
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fix #37751
| License | MIT
| Doc PR | -
Commits
-------
55c17e1af7
[Validator] Add support for UUIDv6 in Uuid constraint
This commit is contained in:
commit
af8ad344d3
@ -31,6 +31,7 @@ CHANGELOG
|
|||||||
```
|
```
|
||||||
* added the `Isin` constraint and validator
|
* added the `Isin` constraint and validator
|
||||||
* added the `ULID` constraint and validator
|
* added the `ULID` constraint and validator
|
||||||
|
* added support for UUIDv6 in `Uuid` constraint
|
||||||
|
|
||||||
5.1.0
|
5.1.0
|
||||||
-----
|
-----
|
||||||
|
@ -44,6 +44,7 @@ class Uuid extends Constraint
|
|||||||
const V3_MD5 = 3;
|
const V3_MD5 = 3;
|
||||||
const V4_RANDOM = 4;
|
const V4_RANDOM = 4;
|
||||||
const V5_SHA1 = 5;
|
const V5_SHA1 = 5;
|
||||||
|
const V6_SORTABLE = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message to display when validation fails.
|
* Message to display when validation fails.
|
||||||
@ -74,6 +75,7 @@ class Uuid extends Constraint
|
|||||||
self::V3_MD5,
|
self::V3_MD5,
|
||||||
self::V4_RANDOM,
|
self::V4_RANDOM,
|
||||||
self::V5_SHA1,
|
self::V5_SHA1,
|
||||||
|
self::V6_SORTABLE,
|
||||||
];
|
];
|
||||||
|
|
||||||
public $normalizer;
|
public $normalizer;
|
||||||
|
@ -22,14 +22,11 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
|||||||
* Strict validation will allow a UUID as specified per RFC 4122.
|
* Strict validation will allow a UUID as specified per RFC 4122.
|
||||||
* Loose validation will allow any type of UUID.
|
* Loose validation will allow any type of UUID.
|
||||||
*
|
*
|
||||||
* For better compatibility, both loose and strict, you should consider using a specialized UUID library like "ramsey/uuid" instead.
|
|
||||||
*
|
|
||||||
* @author Colin O'Dell <colinodell@gmail.com>
|
* @author Colin O'Dell <colinodell@gmail.com>
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*
|
*
|
||||||
* @see http://tools.ietf.org/html/rfc4122
|
* @see http://tools.ietf.org/html/rfc4122
|
||||||
* @see https://en.wikipedia.org/wiki/Universally_unique_identifier
|
* @see https://en.wikipedia.org/wiki/Universally_unique_identifier
|
||||||
* @see https://github.com/ramsey/uuid
|
|
||||||
*/
|
*/
|
||||||
class UuidValidator extends ConstraintValidator
|
class UuidValidator extends ConstraintValidator
|
||||||
{
|
{
|
||||||
@ -38,7 +35,7 @@ class UuidValidator extends ConstraintValidator
|
|||||||
|
|
||||||
// Roughly speaking:
|
// Roughly speaking:
|
||||||
// x = any hexadecimal character
|
// x = any hexadecimal character
|
||||||
// M = any allowed version {1..5}
|
// M = any allowed version {1..6}
|
||||||
// N = any allowed variant {8, 9, a, b}
|
// N = any allowed variant {8, 9, a, b}
|
||||||
|
|
||||||
const STRICT_LENGTH = 36;
|
const STRICT_LENGTH = 36;
|
||||||
|
@ -78,6 +78,7 @@ class UuidValidatorTest extends ConstraintValidatorTestCase
|
|||||||
['456daefb-5aa6-41b5-8dbc-068b05a8b201'], // Version 4 UUID in lowercase
|
['456daefb-5aa6-41b5-8dbc-068b05a8b201'], // Version 4 UUID in lowercase
|
||||||
['456daEFb-5AA6-41B5-8DBC-068B05A8B201'], // Version 4 UUID in mixed case
|
['456daEFb-5AA6-41B5-8DBC-068B05A8B201'], // Version 4 UUID in mixed case
|
||||||
['456daEFb-5AA6-41B5-8DBC-068B05A8B201', [Uuid::V4_RANDOM]],
|
['456daEFb-5AA6-41B5-8DBC-068B05A8B201', [Uuid::V4_RANDOM]],
|
||||||
|
['1eb01932-4c0b-6570-aa34-d179cdf481ae', [Uuid::V6_SORTABLE]],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +146,6 @@ class UuidValidatorTest extends ConstraintValidatorTestCase
|
|||||||
['216fff40-98d9-11e3-a5e2-0800200c9a6', Uuid::TOO_SHORT_ERROR],
|
['216fff40-98d9-11e3-a5e2-0800200c9a6', Uuid::TOO_SHORT_ERROR],
|
||||||
['216fff40-98d9-11e3-a5e2-0800200c9a666', Uuid::TOO_LONG_ERROR],
|
['216fff40-98d9-11e3-a5e2-0800200c9a666', Uuid::TOO_LONG_ERROR],
|
||||||
['216fff40-98d9-01e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
['216fff40-98d9-01e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
||||||
['216fff40-98d9-61e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
|
||||||
['216fff40-98d9-71e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
['216fff40-98d9-71e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
||||||
['216fff40-98d9-81e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
['216fff40-98d9-81e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
||||||
['216fff40-98d9-91e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
['216fff40-98d9-91e3-a5e2-0800200c9a66', Uuid::INVALID_VERSION_ERROR],
|
||||||
|
Reference in New Issue
Block a user