Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7572a5

Browse files
feature#58246 [Serializer][Uid] Add theUuid::FORMAT_RFC_9562 andUidNormalizer::NORMALIZATION_FORMAT_RFC9562 constants (alexandre-daubois)
This PR was merged into the 7.2 branch.Discussion----------[Serializer][Uid] Add the `Uuid::FORMAT_RFC_9562` and `UidNormalizer::NORMALIZATION_FORMAT_RFC9562` constants| Q | A| ------------- | ---| Branch? | 7.2| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues | -| License | MITFollowing#58238 (cc `@fancyweb`), for completeness of this 7.2 feature.Commits-------f84170a [Serializer][Uid] Add the `Uuid::FORMAT_RFC_9562` and `UidNormalizer::NORMALIZATION_FORMAT_RFC9562` constants
2 parents0487a08 +f84170a commitb7572a5

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

‎src/Symfony/Component/Serializer/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Deprecate`CsvEncoderContextBuilder::withEscapeChar()` method
99
* Add`SnakeCaseToCamelCaseNameConverter`
1010
* Support subclasses of`\DateTime` and`\DateTimeImmutable` for denormalization
11+
* Add the`UidNormalizer::NORMALIZATION_FORMAT_RFC9562` constant
1112

1213
7.1
1314
---

‎src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ final class UidNormalizer implements NormalizerInterface, DenormalizerInterface
2323
publicconstNORMALIZATION_FORMAT_BASE58 ='base58';
2424
publicconstNORMALIZATION_FORMAT_BASE32 ='base32';
2525
publicconstNORMALIZATION_FORMAT_RFC4122 ='rfc4122';
26+
publicconstNORMALIZATION_FORMAT_RFC9562 =self::NORMALIZATION_FORMAT_RFC4122;
2627
publicconstNORMALIZATION_FORMATS = [
2728
self::NORMALIZATION_FORMAT_CANONICAL,
2829
self::NORMALIZATION_FORMAT_BASE58,

‎src/Symfony/Component/Uid/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Make`AbstractUid` implement`Ds\Hashable` if available
88
* Add support for binary, base-32 and base-58 representations in`Uuid::isValid()`
9+
* Add the`Uuid::FORMAT_RFC_9562` constant to validate UUIDs in the RFC 9562 format
910

1011
7.1
1112
---

‎src/Symfony/Component/Uid/Tests/UuidTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ public function testIsValidWithVariousFormat()
237237
$this->assertFalse(Uuid::isValid($uuid->toBinary(), Uuid::FORMAT_RFC_4122));
238238
$this->assertTrue(Uuid::isValid($uuid->toRfc4122(), Uuid::FORMAT_RFC_4122));
239239

240+
$this->assertFalse(Uuid::isValid($uuid->toBase32(), Uuid::FORMAT_RFC_9562));
241+
$this->assertFalse(Uuid::isValid($uuid->toBase58(), Uuid::FORMAT_RFC_9562));
242+
$this->assertFalse(Uuid::isValid($uuid->toBinary(), Uuid::FORMAT_RFC_9562));
243+
$this->assertTrue(Uuid::isValid($uuid->toRfc4122(), Uuid::FORMAT_RFC_9562));
244+
240245
$this->assertTrue(Uuid::isValid($uuid->toBase32(), Uuid::FORMAT_ALL));
241246
$this->assertTrue(Uuid::isValid($uuid->toBase58(), Uuid::FORMAT_ALL));
242247
$this->assertTrue(Uuid::isValid($uuid->toBinary(), Uuid::FORMAT_ALL));

‎src/Symfony/Component/Uid/Uuid.php‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Uuid extends AbstractUid
2727
publicconstFORMAT_BASE_32 =1 <<1;
2828
publicconstFORMAT_BASE_58 =1 <<2;
2929
publicconstFORMAT_RFC_4122 =1 <<3;
30+
publicconstFORMAT_RFC_9562 =self::FORMAT_RFC_4122;
3031
publicconstFORMAT_ALL = -1;
3132

3233
protectedconstTYPE =0;
@@ -50,7 +51,7 @@ public function __construct(string $uuid, bool $checkVariant = false)
5051

5152
publicstaticfunctionfromString(string$uuid):static
5253
{
53-
$uuid =self::transformToRfc4122($uuid,self::FORMAT_ALL);
54+
$uuid =self::transformToRfc9562($uuid,self::FORMAT_ALL);
5455

5556
if (__CLASS__ !==static::class ||36 !==\strlen($uuid)) {
5657
returnnewstatic($uuid);
@@ -124,15 +125,15 @@ final public static function v8(string $uuid): UuidV8
124125
/**
125126
* @param int-mask-of<Uuid::FORMAT_*> $format
126127
*/
127-
publicstaticfunctionisValid(string$uuid/* , int $format = self::FORMAT_RFC_4122 */):bool
128+
publicstaticfunctionisValid(string$uuid/* , int $format = self::FORMAT_RFC_9562 */):bool
128129
{
129-
$format =1 <\func_num_args() ?func_get_arg(1) :self::FORMAT_RFC_4122;
130+
$format =1 <\func_num_args() ?func_get_arg(1) :self::FORMAT_RFC_9562;
130131

131-
if (36 ===\strlen($uuid) && !($format &self::FORMAT_RFC_4122)) {
132+
if (36 ===\strlen($uuid) && !($format &self::FORMAT_RFC_9562)) {
132133
returnfalse;
133134
}
134135

135-
if (false ===$uuid =self::transformToRfc4122($uuid,$format)) {
136+
if (false ===$uuid =self::transformToRfc9562($uuid,$format)) {
136137
returnfalse;
137138
}
138139

@@ -188,13 +189,13 @@ private static function format(string $uuid, string $version): string
188189
}
189190

190191
/**
191-
* Transforms a binary string, a base-32 string or a base-58 string to aRFC4122 string.
192+
* Transforms a binary string, a base-32 string or a base-58 string to aRFC9562 string.
192193
*
193194
* @param int-mask-of<Uuid::FORMAT_*> $format
194195
*
195-
* @return string|false TheRFC4122 string or false if the format doesn't match the input
196+
* @return string|false TheRFC9562 string or false if the format doesn't match the input
196197
*/
197-
privatestaticfunctiontransformToRfc4122(string$uuid,int$format):string|false
198+
privatestaticfunctiontransformToRfc9562(string$uuid,int$format):string|false
198199
{
199200
$inputUuid =$uuid;
200201
$fromBase58 =false;
@@ -217,7 +218,7 @@ private static function transformToRfc4122(string $uuid, int $format): string|fa
217218
$uuid =$ulid->toRfc4122();
218219
}
219220

220-
if ($inputUuid ===$uuid && !($format &self::FORMAT_RFC_4122)) {
221+
if ($inputUuid ===$uuid && !($format &self::FORMAT_RFC_9562)) {
221222
// input format doesn't match the input string
222223
returnfalse;
223224
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp