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

Commitbd3fedf

Browse files
committed
feature#61812 [Uid] Default toUuidV7 when usingUuidFactory (nicolas-grekas)
This PR was merged into the 7.4 branch.Discussion----------[Uid] Default to `UuidV7` when using `UuidFactory`| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | no| New feature? | no| Deprecations? | no| Issues | -| License | MITUUIDv7 are how time-based UUIDs should have been from day 1 :)(+ some minor optims to Ulid while at it.)Commits-------2cc4f5f [Uid] Default to `UuidV7` when using `UuidFactory`
2 parents2a2c16d +2cc4f5f commitbd3fedf

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

‎UPGRADE-7.4.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ Translation
109109

110110
* Deprecate`TranslatableMessage::__toString`
111111

112+
Uid
113+
---
114+
115+
* Default to`UuidV7` when using`UuidFactory`
116+
112117
Validator
113118
---------
114119

‎src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidGeneratorTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
usePHPUnit\Framework\TestCase;
1616
useSymfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
1717
useSymfony\Component\Uid\Factory\UuidFactory;
18+
useSymfony\Component\Uid\TimeBasedUidInterface;
1819
useSymfony\Component\Uid\Uuid;
1920
useSymfony\Component\Uid\UuidV4;
20-
useSymfony\Component\Uid\UuidV6;
2121

2222
class UuidGeneratorTestextends TestCase
2323
{
@@ -47,13 +47,13 @@ public function testUuidfactory()
4747
{
4848
$em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
4949
$generator =newUuidGenerator();
50-
$this->assertInstanceOf(UuidV6::class,$generator->generate($em,newEntity()));
50+
$this->assertInstanceOf(TimeBasedUidInterface::class,$generator->generate($em,newEntity()));
5151

5252
$generator =$generator->randomBased();
5353
$this->assertInstanceOf(UuidV4::class,$generator->generate($em,newEntity()));
5454

5555
$generator =$generator->timeBased();
56-
$this->assertInstanceOf(UuidV6::class,$generator->generate($em,newEntity()));
56+
$this->assertInstanceOf(TimeBasedUidInterface::class,$generator->generate($em,newEntity()));
5757

5858
$generator =$generator->nameBased('prop1', Uuid::NAMESPACE_OID);
5959
$this->assertEquals(Uuid::v5(newUuid(Uuid::NAMESPACE_OID),'3'),$generator->generate($em,newEntity()));

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

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

77
* Add microsecond precision to UUIDv7
8+
* Default to`UuidV7` when using`UuidFactory`
89

910
7.3
1011
---

‎src/Symfony/Component/Uid/Factory/UuidFactory.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
useSymfony\Component\Uid\UuidV1;
1717
useSymfony\Component\Uid\UuidV4;
1818
useSymfony\Component\Uid\UuidV5;
19-
useSymfony\Component\Uid\UuidV6;
19+
useSymfony\Component\Uid\UuidV7;
2020

2121
class UuidFactory
2222
{
@@ -27,7 +27,7 @@ class UuidFactory
2727
private ?Uuid$timeBasedNode;
2828
private ?Uuid$nameBasedNamespace;
2929

30-
publicfunction__construct(string|int$defaultClass =UuidV6::class,string|int$timeBasedClass =UuidV6::class,string|int$nameBasedClass = UuidV5::class,string|int$randomBasedClass = UuidV4::class,Uuid|string|null$timeBasedNode =null,Uuid|string|null$nameBasedNamespace =null)
30+
publicfunction__construct(string|int$defaultClass =UuidV7::class,string|int$timeBasedClass =UuidV7::class,string|int$nameBasedClass = UuidV5::class,string|int$randomBasedClass = UuidV4::class,Uuid|string|null$timeBasedNode =null,Uuid|string|null$nameBasedNamespace =null)
3131
{
3232
if (null !==$timeBasedNode && !$timeBasedNodeinstanceof Uuid) {
3333
$timeBasedNode = Uuid::fromString($timeBasedNode);

‎src/Symfony/Component/Uid/Tests/Command/GenerateUuidCommandTest.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
useSymfony\Component\Uid\UuidV3;
2424
useSymfony\Component\Uid\UuidV4;
2525
useSymfony\Component\Uid\UuidV5;
26-
useSymfony\Component\Uid\UuidV6;
26+
useSymfony\Component\Uid\UuidV7;
2727

2828
finalclass GenerateUuidCommandTestextends TestCase
2929
{
3030
publicfunctiontestDefaults()
3131
{
3232
$commandTester =newCommandTester(newGenerateUuidCommand());
3333
$this->assertSame(0,$commandTester->execute([]));
34-
$this->assertInstanceOf(UuidV6::class, Uuid::fromRfc4122(trim($commandTester->getDisplay())));
34+
$this->assertInstanceOf(UuidV7::class, Uuid::fromRfc4122(trim($commandTester->getDisplay())));
3535

3636
$commandTester =newCommandTester(newGenerateUuidCommand(newUuidFactory(UuidV4::class)));
3737
$this->assertSame(0,$commandTester->execute([]));
@@ -59,17 +59,17 @@ public function testTimeBasedWithTimestampBeforeUUIDEpoch()
5959
$commandTester =newCommandTester(newGenerateUuidCommand());
6060

6161
$this->assertSame(1,$commandTester->execute(['--time-based' =>'@-16807797990']));
62-
$this->assertStringContainsString('Thegiven UUID date cannotbeearlier than 1582-10-15.',$commandTester->getDisplay());
62+
$this->assertStringContainsString('Thetimestamp mustbepositive.',$commandTester->getDisplay());
6363
}
6464

6565
publicfunctiontestTimeBased()
6666
{
6767
$commandTester =newCommandTester(newGenerateUuidCommand());
6868
$this->assertSame(0,$commandTester->execute(['--time-based' =>'now']));
69-
$this->assertInstanceOf(UuidV6::class, Uuid::fromRfc4122(trim($commandTester->getDisplay())));
69+
$this->assertInstanceOf(UuidV7::class, Uuid::fromRfc4122(trim($commandTester->getDisplay())));
7070

7171
$commandTester =newCommandTester(newGenerateUuidCommand(newUuidFactory(
72-
UuidV6::class,
72+
UuidV7::class,
7373
UuidV1::class,
7474
UuidV5::class,
7575
UuidV4::class,
@@ -104,7 +104,7 @@ public function testNameBased()
104104
$this->assertInstanceOf(UuidV5::class, Uuid::fromRfc4122(trim($commandTester->getDisplay())));
105105

106106
$commandTester =newCommandTester(newGenerateUuidCommand(newUuidFactory(
107-
UuidV6::class,
107+
UuidV7::class,
108108
UuidV1::class,
109109
UuidV3::class,
110110
UuidV4::class,

‎src/Symfony/Component/Uid/Tests/Factory/UuidFactoryTest.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
useSymfony\Component\Uid\UuidV4;
2222
useSymfony\Component\Uid\UuidV5;
2323
useSymfony\Component\Uid\UuidV6;
24+
useSymfony\Component\Uid\UuidV7;
2425

2526
finalclass UuidFactoryTestextends TestCase
2627
{
@@ -51,7 +52,7 @@ public function testCreateNamed()
5152

5253
publicfunctiontestCreateTimedDefaultVersion()
5354
{
54-
$this->assertInstanceOf(UuidV6::class, (newUuidFactory())->timeBased()->create());
55+
$this->assertInstanceOf(UuidV7::class, (newUuidFactory())->timeBased()->create());
5556
$this->assertInstanceOf(UuidV1::class, (newUuidFactory(6,1))->timeBased()->create());
5657
}
5758

@@ -83,7 +84,7 @@ public function testCreateTimed()
8384
publicfunctiontestInvalidCreateTimed()
8485
{
8586
$this->expectException(InvalidArgumentException::class);
86-
$this->expectExceptionMessage('Thegiven UUID date cannotbeearlier than 1582-10-15.');
87+
$this->expectExceptionMessage('Thetimestamp mustbepositive.');
8788

8889
(newUuidFactory())->timeBased()->create(new \DateTimeImmutable('@-12219292800.001000'));
8990
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public function __construct(?string $ulid = null)
3333
if (null ===$ulid) {
3434
$this->uid =static::generate();
3535
}elseif (self::NIL ===$ulid) {
36-
$this->uid =$ulid;
37-
}elseif (self::MAX ===strtr($ulid,'z','Z')) {
38-
$this->uid =$ulid;
36+
$this->uid =self::NIL;
3937
}else {
40-
if (!self::isValid($ulid)) {
38+
$this->uid =strtoupper($ulid);
39+
40+
if (self::MAX ===$this->uid) {
41+
$this->uid =self::MAX;
42+
}elseif (!self::isValid($ulid)) {
4143
thrownewInvalidArgumentException(\sprintf('Invalid ULID: "%s".',$ulid));
4244
}
43-
44-
$this->uid =strtoupper($ulid);
4545
}
4646
}
4747

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp