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

Commit09db71f

Browse files
committed
Added toHexString method to AbstractUid class
1 parent3c07197 commit09db71f

File tree

7 files changed

+34
-0
lines changed

7 files changed

+34
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ public function toRfc4122(): string
127127
returnsubstr_replace($uuid,'-',23,0);
128128
}
129129

130+
/**
131+
* Returns the identifier as a prefixed hexadecimal case insensitive string.
132+
*/
133+
publicfunctiontoHex():string
134+
{
135+
return'0x' .bin2hex($this->toBinary());
136+
}
137+
130138
/**
131139
* Returns whether the argument is an AbstractUid and contains the same value as the current instance.
132140
*/

‎src/Symfony/Component/Uid/Command/InspectUlidCommand.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6363
['toBase32 (canonical)', (string)$ulid],
6464
['toBase58',$ulid->toBase58()],
6565
['toRfc4122',$ulid->toRfc4122()],
66+
['toHex',$ulid->toHex()],
6667
newTableSeparator(),
6768
['Time', ($ulid->getDateTime())->format('Y-m-d H:i:s.v \U\T\C')],
6869
]);

‎src/Symfony/Component/Uid/Command/InspectUuidCommand.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7373
['toRfc4122 (canonical)', (string)$uuid],
7474
['toBase58',$uuid->toBase58()],
7575
['toBase32',$uuid->toBase32()],
76+
['toHex',$uuid->toHex()],
7677
];
7778

7879
if ($uuidinstanceof UuidV1 ||$uuidinstanceof UuidV6) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function test()
3737
toBase32 (canonical) 01E439TP9XJZ9RPFH3T1PYBCR8
3838
toBase58 1BKocMc5BnrVcuq2ti4Eqm
3939
toRfc4122 0171069d-593d-97d3-8b3e-23d06de5b308
40+
toHex 0x0171069d593d97d38b3e23d06de5b308
4041
---------------------- --------------------------------------
4142
Time 2020-03-23 08:58:27.517 UTC
4243
---------------------- --------------------------------------

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function testNil()
3838
toRfc4122 (canonical) 00000000-0000-0000-0000-000000000000
3939
toBase58 1111111111111111111111
4040
toBase32 00000000000000000000000000
41+
toHex 0x00000000000000000000000000000000
4142
----------------------- --------------------------------------
4243
4344
@@ -58,6 +59,7 @@ public function testUnknown()
5859
toRfc4122 (canonical) 461cc9b9-2397-0dba-91e9-33af4c63f7ec
5960
toBase58 9f9nftX6dw4oVPm5uT17um
6061
toBase32 263K4VJ8WQ1PX93T9KNX667XZC
62+
toHex 0x461cc9b923970dba91e933af4c63f7ec
6163
----------------------- --------------------------------------
6264
6365
@@ -73,6 +75,7 @@ public function testUnknown()
7375
toRfc4122 (canonical) 461cc9b9-2397-2dba-91e9-33af4c63f7ec
7476
toBase58 9f9nftX6fjLfNnvSAHMV7Z
7577
toBase32 263K4VJ8WQ5PX93T9KNX667XZC
78+
toHex 0x461cc9b923972dba91e933af4c63f7ec
7679
----------------------- --------------------------------------
7780
7881
@@ -88,6 +91,7 @@ public function testUnknown()
8891
toRfc4122 (canonical) 461cc9b9-2397-7dba-91e9-33af4c63f7ec
8992
toBase58 9f9nftX6kE2K6HpooNEQ83
9093
toBase32 263K4VJ8WQFPX93T9KNX667XZC
94+
toHex 0x461cc9b923977dba91e933af4c63f7ec
9195
----------------------- --------------------------------------
9296
9397
@@ -103,6 +107,7 @@ public function testUnknown()
103107
toRfc4122 (canonical) 461cc9b9-2397-cdba-91e9-33af4c63f7ec
104108
toBase58 9f9nftX6pihxonjBST7K8X
105109
toBase32 263K4VJ8WQSPX93T9KNX667XZC
110+
toHex 0x461cc9b92397cdba91e933af4c63f7ec
106111
----------------------- --------------------------------------
107112
108113
@@ -123,6 +128,7 @@ public function testV1()
123128
toRfc4122 (canonical) 4c8e3a2a-5993-11eb-a861-2bf05af69e52
124129
toBase58 ATJGVdrgFqvc6thDFXv1Qu
125130
toBase32 2CHRX2MPCK27NTGR9BY1DFD7JJ
131+
toHex 0x4c8e3a2a599311eba8612bf05af69e52
126132
----------------------- --------------------------------------
127133
Time 2021-01-18 13:44:34.438609 UTC
128134
----------------------- --------------------------------------
@@ -145,6 +151,7 @@ public function testV3()
145151
toRfc4122 (canonical) d108a1a0-957e-3c77-b110-d3f912374439
146152
toBase58 Sp7q16VVeC7zPsMPVEToq2
147153
toBase32 6H12GT15BY7HVV246KZ493EH1S
154+
toHex 0xd108a1a0957e3c77b110d3f912374439
148155
----------------------- --------------------------------------
149156
150157
@@ -165,6 +172,7 @@ public function testV4()
165172
toRfc4122 (canonical) 705c6eab-a535-4f49-bd51-436d0e81206a
166173
toBase58 EsjuVs1nd42xt7jSB8hNQH
167174
toBase32 3GBHQAQ99N9X4VTMA3DM78283A
175+
toHex 0x705c6eaba5354f49bd51436d0e81206a
168176
----------------------- --------------------------------------
169177
170178
@@ -185,6 +193,7 @@ public function testV5()
185193
toRfc4122 (canonical) 4ec6c3ad-de94-5f75-b5f0-ad56661a30c4
186194
toBase58 AjCoyQeK6TtFemqYWV5uKZ
187195
toBase32 2ERV1TVQMMBXTVBW5DASK1MC64
196+
toHex 0x4ec6c3adde945f75b5f0ad56661a30c4
188197
----------------------- --------------------------------------
189198
190199
@@ -205,6 +214,7 @@ public function testV6()
205214
toRfc4122 (canonical) 1eb59937-b0a7-6288-a861-db3dc2d8d4db
206215
toBase58 4nwhs6vwvNU2AbcCSD1XP8
207216
toBase32 0YPPCKFC57CA4AGREV7Q1DHN6V
217+
toHex 0x1eb59937b0a76288a861db3dc2d8d4db
208218
----------------------- --------------------------------------
209219
Time 2021-01-18 13:45:52.427892 UTC
210220
----------------------- --------------------------------------

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ public function testBinary()
5252
$this->assertTrue($ulid->equals(Ulid::fromString(hex2bin('7fffffffffffffffffffffffffffffff'))));
5353
}
5454

55+
publicfunctiontoHex()
56+
{
57+
$ulid = Ulid::fromString('1BVXue8CnY8ogucrHX3TeF');
58+
$this->assertSame('0x0177058f4dacd0b2a990a49af02bc008',$ulid->toHex());
59+
}
60+
5561
publicfunctiontestFromUuid()
5662
{
5763
$uuid =newUuidV4();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ public function testBinary()
116116
$this->assertSame(self::A_UUID_V4, (string)$uuid);
117117
}
118118

119+
publicfunctiontestHex()
120+
{
121+
$uuid =newUuidV4(self::A_UUID_V4);
122+
123+
$this->assertSame('0xd6b3345b29054048a83cb5988e765d98',$uuid->toHex());
124+
}
125+
119126
publicfunctiontestFromUlid()
120127
{
121128
$ulid =newUlid();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp