-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Uid] Default to UuidV7 when using UuidFactory #21408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
components/uid.rst
Outdated
configure the behavior of the factory using configuration files:: | ||
You can also use the ``UuidFactory`` to generate UUIDs. By default, this factory | ||
uses UUIDv7 for default and time-based UUIDs, UUIDv5 for name-based UUIDS, and | ||
UUIDv4 for random-based UUIDs, but you can configure this behavior:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably update the config example to use other versions than 7 for the default and time based UUID version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I submitted some changes. Thanks.
components/uid.rst
Outdated
{ | ||
$uuid = $this->uuidFactory->create(); | ||
|
||
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nameBased()
, timeBased()
and randomBased()
methods don't return a UUID directly, but return a factory instead on which we then have to call create()
. So this example would have to look like this:
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */); | |
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */)->create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->create($name)
actually (the argument of nameBased is optional if the factory is configured with a default namespace)
components/uid.rst
Outdated
|
||
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */); | ||
$randomBasedUuid = $this->uuidFactory->randomBased(); | ||
$timestampBased = $this->uuidFactory->timeBased(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$timestampBased = $this->uuidFactory->timeBased(); | |
$timestampBased = $this->uuidFactory->timeBased()->create(); |
components/uid.rst
Outdated
$uuid = $this->uuidFactory->create(); | ||
|
||
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */); | ||
$randomBasedUuid = $this->uuidFactory->randomBased(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$randomBasedUuid = $this->uuidFactory->randomBased(); | |
$randomBasedUuid = $this->uuidFactory->randomBased()->create(); |
components/uid.rst
Outdated
} | ||
} | ||
Starting from Symfony 7.4, the default version for both UUIDs and time-based | ||
UUIDs is UUIDv7. In previous versions, the default was UUIDv6. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UUIDs is UUIDv7. In previous versions, the default was UUIDv6. | |
UUIDs is v7. In previous versions, the default was v6. |
Thanks for the review, folks! I made some changes. |
components/uid.rst
Outdated
|
||
$randomBasedUuid = $this->uuidFactory->randomBased()->create(); | ||
// $namespace can be omitted if a default is configured in the factory (see below) | ||
$nameBasedUuid = $this->uuidFactory->nameBased($namespace)->create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$nameBasedUuid = $this->uuidFactory->nameBased($namespace)->create(); | |
$nameBasedUuid = $this->uuidFactory->nameBased($namespace)->create($name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this. Added. Thanks!
34fcdcb
to
e918166
Compare
Fixes #21403.