diff --git a/src/Symfony/Component/Uid/AbstractUid.php b/src/Symfony/Component/Uid/AbstractUid.php index 172f095022700..b65fa44f5b551 100644 --- a/src/Symfony/Component/Uid/AbstractUid.php +++ b/src/Symfony/Component/Uid/AbstractUid.php @@ -164,6 +164,11 @@ public function compare(self $other): int return (\strlen($this->uid) - \strlen($other->uid)) ?: ($this->uid <=> $other->uid); } + final public function toString(): string + { + return $this->__toString(); + } + public function __toString(): string { return $this->uid; diff --git a/src/Symfony/Component/Uid/CHANGELOG.md b/src/Symfony/Component/Uid/CHANGELOG.md index dd28dd6a54c49..8fea6eb6ecbf9 100644 --- a/src/Symfony/Component/Uid/CHANGELOG.md +++ b/src/Symfony/Component/Uid/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Add `UuidV1::toV6()`, `UuidV1::toV7()` and `UuidV6::toV7()` + * Add `AbstractUid::toString()` 6.2 --- diff --git a/src/Symfony/Component/Uid/Tests/UlidTest.php b/src/Symfony/Component/Uid/Tests/UlidTest.php index 6669befadf811..338b699159a77 100644 --- a/src/Symfony/Component/Uid/Tests/UlidTest.php +++ b/src/Symfony/Component/Uid/Tests/UlidTest.php @@ -290,4 +290,9 @@ public function testNewMaxUlid() { $this->assertSame('7ZZZZZZZZZZZZZZZZZZZZZZZZZ', (string) new MaxUlid()); } + + public function testToString() + { + $this->assertSame('01HK77WP8T7107EZH9CNAES202', (new Ulid('01HK77WP8T7107EZH9CNAES202'))->toString()); + } } diff --git a/src/Symfony/Component/Uid/Tests/UuidTest.php b/src/Symfony/Component/Uid/Tests/UuidTest.php index 297f85cb99993..834fb5d26dd83 100644 --- a/src/Symfony/Component/Uid/Tests/UuidTest.php +++ b/src/Symfony/Component/Uid/Tests/UuidTest.php @@ -471,4 +471,9 @@ public function testV1ToV7WhenExtraTimeEntropyOverflows() $this->assertNotEquals($uuidV7, $sameUuidV7100NanosecondsLater); $this->assertSame(hexdec('0'.substr($uuidV7, -2)) + 1, hexdec('0'.substr($sameUuidV7100NanosecondsLater, -2))); } + + public function testToString() + { + $this->assertSame('a45a8538-77a9-4335-bd30-236f59b81b81', (new UuidV4('a45a8538-77a9-4335-bd30-236f59b81b81'))->toString()); + } }