Skip to content

Commit e0d44f5

Browse files
committed
Fixes and improvements
1 parent ac6c642 commit e0d44f5

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

components/uid.rst

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,33 @@ Use the named constructors of the ``Uuid`` class or any of the specific classes
3737
to create each type of UUID::
3838

3939
use Symfony\Component\Uid\Uuid;
40-
use Symfony\Component\Uid\UuidV1;
41-
use Symfony\Component\Uid\UuidV3;
42-
use Symfony\Component\Uid\UuidV4;
43-
use Symfony\Component\Uid\UuidV5;
44-
use Symfony\Component\Uid\UuidV6;
4540

4641
// UUID type 1 generates the UUID using the MAC address of your device and a timestamp.
4742
// Both are obtained automatically, so you don't have to pass any constructor argument.
48-
$uuid = Uuid::v1();
49-
$uuid = new UuidV1();
43+
$uuid = Uuid::v1(); // $uuid is an instance of Symfony\Component\Uid\UuidV1
5044

5145
// UUID type 4 generates a random UUID, so you don't have to pass any constructor argument.
52-
$uuid = Uuid::v4();
53-
$uuid = new UuidV4();
46+
$uuid = Uuid::v4(); // $uuid is an instance of Symfony\Component\Uid\UuidV4
5447

5548
// UUID type 3 and 5 generate a UUID hashing the given namespace and name. Type 3 uses
5649
// MD5 hashes and Type 5 uses SHA-1. The namespace is another UUID (e.g. a Type 4 UUID)
5750
// and the name is an arbitrary string (e.g. a product name; if it's unique).
58-
$namespace = new UuidV4();
51+
$namespace = Uuid::v4();
5952
$name = $product->getUniqueName();
6053

61-
$uuid = Uuid::v3($namespace, $name);
62-
$uuid = new UuidV3($namespace, $name);
63-
64-
$uuid = Uuid::v5($namespace, $name);
65-
$uuid = new UuidV5($namespace, $name);
54+
$uuid = Uuid::v3($namespace, $name); // $uuid is an instance of Symfony\Component\Uid\UuidV3
55+
$uuid = Uuid::v5($namespace, $name); // $uuid is an instance of Symfony\Component\Uid\UuidV5
6656

6757
// UUID type 6 is not part of the UUID standard. It's lexicographically sortable
6858
// (like ULIDs) and contains a 60-bit timestamp and 63 extra unique bits.
6959
// It's defined in http://gh.peabody.io/uuidv6/
70-
$uuid = Uuid::v6();
71-
$uuid = new UuidV6();
60+
$uuid = Uuid::v6(); // $uuid is an instance of Symfony\Component\Uid\UuidV6
7261

73-
If your UUID is generated by another system, use the regular constructor of the
74-
``Uuid`` class (or the static ``fromString()`` method) to create an object and
75-
make use of the utilities available for Symfony UUIDs::
62+
If your UUID is generated by another system, use the ``fromString()`` method to
63+
create an object and make use of the utilities available for Symfony UUIDs::
7664

7765
// this value is generated somewhere else
7866
$uuidValue = 'd9e7a184-5d5b-11ea-a62a-3499710062d0';
79-
$uuid = new Uuid($uuidValue);
8067
$uuid = Uuid::fromString($uuidValue);
8168

8269
If your UUIDs are generated in binary format, use the ``fromBinary()`` method
@@ -89,8 +76,7 @@ Converting UUIDs
8976

9077
Use these methods to transform the UUID object into different bases::
9178

92-
$uuidValue = 'd9e7a184-5d5b-11ea-a62a-3499710062d0';
93-
$uuid = new Uuid($uuidValue);
79+
$uuid = new Uuid::fromString('d9e7a184-5d5b-11ea-a62a-3499710062d0');
9480

9581
$uuid->toBinary(); // string(16) "..." (binary contents can't be printed)
9682
$uuid->toBase32(); // string(26) "6SWYGR8QAV27NACAHMK5RG0RPG"
@@ -103,8 +89,8 @@ Working with UUIDs
10389
UUID objects created with the ``Uuid`` class can use the following methods
10490
(which are equivalent to the ``uuid_*()`` method of the PHP extension)::
10591

106-
use Symfony\Component\Uid\Uuid;
10792
use Symfony\Component\Uid\NilUuid;
93+
use Symfony\Component\Uid\Uuid;
10894

10995
// checking if the UUID is null (note that the class is called
11096
// NilUuid instead of NullUuid to follow the UUID standard notation)
@@ -151,10 +137,12 @@ Instantiate the ``Ulid`` class to generate a random ULID value::
151137

152138
$ulid = new Ulid(); // e.g. 01AN4Z07BY79KA1307SR9X4MV3
153139

154-
If your ULID is generated by another system, pass its value to the constructor::
140+
If your UUID is generated by another system, use the ``fromString()`` method to
141+
create an object and make use of the utilities available for Symfony ULIDs::
155142

143+
// this value is generated somewhere else
156144
$ulidValue = '01E439TP9XJZ9RPFH3T1PYBCR8';
157-
$ulid = new Ulid($ulidValue);
145+
$ulid = Ulid::fromString($ulidValue);
158146

159147
If your ULIDs are generated in binary format, use the ``fromBinary()`` method
160148
to create the objects for them::
@@ -166,8 +154,7 @@ Converting ULIDs
166154

167155
Use these methods to transform the ULID object into different bases::
168156

169-
$ulidValue = '01E439TP9XJZ9RPFH3T1PYBCR8';
170-
$ulid = new Ulid($ulidValue);
157+
$ulid = Ulid::fromString('01E439TP9XJZ9RPFH3T1PYBCR8');
171158

172159
$ulid->toBinary(); // string(16) "..." (binary contents can't be printed)
173160
$ulid->toBase32(); // string(26) "01E439TP9XJZ9RPFH3T1PYBCR8"

0 commit comments

Comments
 (0)