Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Symfony/Component/Uid/AbstractUid.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ public function toRfc4122(): string
return substr_replace($uuid, '-', 23, 0);
}

/**
* Returns the identifier as a prefixed hexadecimal case insensitive string.
*/
public function toHexString(): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toHex() to be enough and better to me

{
return '0x' . bin2hex($this->toBinary());
}

/**
* Returns whether the argument is an AbstractUid and contains the same value as the current instance.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Uid/Tests/UlidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public function testBinary()
$this->assertTrue($ulid->equals(Ulid::fromString(hex2bin('7fffffffffffffffffffffffffffffff'))));
}

public function testHexString()
{
$ulid = Ulid::fromString('1BVXue8CnY8ogucrHX3TeF');
$this->assertSame('0x0177058f4dacd0b2a990a49af02bc008', $ulid->toHexString());
}

public function testFromUuid()
{
$uuid = new UuidV4();
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Uid/Tests/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public function testBinary()
$this->assertSame(self::A_UUID_V4, (string) $uuid);
}

public function testHexString()
{
$uuid = new UuidV4(self::A_UUID_V4);

$this->assertSame('0xd6b3345b29054048a83cb5988e765d98', $uuid->toHexString());
}

public function testFromUlid()
{
$ulid = new Ulid();
Expand Down