@@ -37,46 +37,33 @@ Use the named constructors of the ``Uuid`` class or any of the specific classes
37
37
to create each type of UUID::
38
38
39
39
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;
45
40
46
41
// UUID type 1 generates the UUID using the MAC address of your device and a timestamp.
47
42
// 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
50
44
51
45
// 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
54
47
55
48
// UUID type 3 and 5 generate a UUID hashing the given namespace and name. Type 3 uses
56
49
// MD5 hashes and Type 5 uses SHA-1. The namespace is another UUID (e.g. a Type 4 UUID)
57
50
// and the name is an arbitrary string (e.g. a product name; if it's unique).
58
- $namespace = new UuidV4 ();
51
+ $namespace = Uuid::v4 ();
59
52
$name = $product->getUniqueName();
60
53
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
66
56
67
57
// UUID type 6 is not part of the UUID standard. It's lexicographically sortable
68
58
// (like ULIDs) and contains a 60-bit timestamp and 63 extra unique bits.
69
59
// 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
72
61
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::
76
64
77
65
// this value is generated somewhere else
78
66
$uuidValue = 'd9e7a184-5d5b-11ea-a62a-3499710062d0';
79
- $uuid = new Uuid($uuidValue);
80
67
$uuid = Uuid::fromString($uuidValue);
81
68
82
69
If your UUIDs are generated in binary format, use the ``fromBinary() `` method
@@ -89,8 +76,7 @@ Converting UUIDs
89
76
90
77
Use these methods to transform the UUID object into different bases::
91
78
92
- $uuidValue = 'd9e7a184-5d5b-11ea-a62a-3499710062d0';
93
- $uuid = new Uuid($uuidValue);
79
+ $uuid = new Uuid::fromString('d9e7a184-5d5b-11ea-a62a-3499710062d0');
94
80
95
81
$uuid->toBinary(); // string(16) "..." (binary contents can't be printed)
96
82
$uuid->toBase32(); // string(26) "6SWYGR8QAV27NACAHMK5RG0RPG"
@@ -103,8 +89,8 @@ Working with UUIDs
103
89
UUID objects created with the ``Uuid `` class can use the following methods
104
90
(which are equivalent to the ``uuid_*() `` method of the PHP extension)::
105
91
106
- use Symfony\Component\Uid\Uuid;
107
92
use Symfony\Component\Uid\NilUuid;
93
+ use Symfony\Component\Uid\Uuid;
108
94
109
95
// checking if the UUID is null (note that the class is called
110
96
// NilUuid instead of NullUuid to follow the UUID standard notation)
@@ -151,10 +137,12 @@ Instantiate the ``Ulid`` class to generate a random ULID value::
151
137
152
138
$ulid = new Ulid(); // e.g. 01AN4Z07BY79KA1307SR9X4MV3
153
139
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::
155
142
143
+ // this value is generated somewhere else
156
144
$ulidValue = '01E439TP9XJZ9RPFH3T1PYBCR8';
157
- $ulid = new Ulid($ulidValue);
145
+ $ulid = Ulid::fromString ($ulidValue);
158
146
159
147
If your ULIDs are generated in binary format, use the ``fromBinary() `` method
160
148
to create the objects for them::
@@ -166,8 +154,7 @@ Converting ULIDs
166
154
167
155
Use these methods to transform the ULID object into different bases::
168
156
169
- $ulidValue = '01E439TP9XJZ9RPFH3T1PYBCR8';
170
- $ulid = new Ulid($ulidValue);
157
+ $ulid = Ulid::fromString('01E439TP9XJZ9RPFH3T1PYBCR8');
171
158
172
159
$ulid->toBinary(); // string(16) "..." (binary contents can't be printed)
173
160
$ulid->toBase32(); // string(26) "01E439TP9XJZ9RPFH3T1PYBCR8"
0 commit comments