You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor #19710 [Uid] Expand the explanation about the different UUID variants (javiereguiluz)
This PR was squashed before being merged into the 6.4 branch.
Discussion
----------
[Uid] Expand the explanation about the different UUID variants
I'm always in favor of making docs as concise as possible, but I think that in this case we should do the opposite and expand the existing docs a bit.
First, the explanation of UUIDs is a very big block of code: https://symfony.com/doc/current/components/uid.html#generating-uuids It looks intimidating and not that clear.
Second, we don't mention many details about some UUIDs, so I propose to add more details.
Lastly, the current examples don't work for UUIDv3 and v5. The given namespace argument must be a `Uuid` object, not a string:
```php
// this does NOT work
$uuid = Uuid::v3(Uuid::NAMESPACE_DNS, $name);
// this WORKS:
$namespace = Uuid::fromString(Uuid::NAMESPACE_OID);
$uuid = Uuid::v3($namespace, 'Hello World');
```
Commits
-------
658edff [Uid] Expand the explanation about the different UUID variants
// $uuid is an instance of Symfony\Component\Uid\UuidV3
70
+
$uuid = Uuid::v3($namespace, $name);
71
+
72
+
These are the default namespaces defined by the standard:
73
+
74
+
* ``Uuid::NAMESPACE_DNS`` if you are generating UUIDs for `DNS entries <https://en.wikipedia.org/wiki/Domain_Name_System>`__
75
+
* ``Uuid::NAMESPACE_URL`` if you are generating UUIDs for `URLs <https://en.wikipedia.org/wiki/URL>`__
76
+
* ``Uuid::NAMESPACE_OID`` if you are generating UUIDs for `OIDs (object identifiers) <https://en.wikipedia.org/wiki/Object_identifier>`__
77
+
* ``Uuid::NAMESPACE_X500`` if you are generating UUIDs for `X500 DNs (distinguished names) <https://en.wikipedia.org/wiki/X.500>`__
78
+
79
+
**UUID v4** (random)
80
+
Generates a random UUID (`read UUIDv4 spec <https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis#name-uuid-version-4>`__).
81
+
Because of its randomness, it ensures uniqueness across distributed systems
82
+
without the need for a central coordinating entity. It's privacy-friendly
83
+
because it doesn't contain any information about where and when it was generated::
84
+
85
+
use Symfony\Component\Uid\Uuid;
86
+
87
+
// $uuid is an instance of Symfony\Component\Uid\UuidV4
88
+
$uuid = Uuid::v4();
89
+
90
+
**UUID v5** (name-based, SHA-1)
91
+
It's the same as UUIDv3 (explained above) but it uses ``sha1`` instead of
92
+
``md5`` to hash the given namespace and name (`read UUIDv5 spec <https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis#name-uuid-version-5>`__).
93
+
This makes it more secure and less prone to hash collisions.
94
+
95
+
**UUID v6** (reordered time-based)
96
+
It rearranges the time-based fields of the UUIDv1 to make it lexicographically
97
+
sortable (like :ref:`ULIDs <ulid>`). It's more efficient for database indexing
0 commit comments