Skip to content

Conversation

javiereguiluz
Copy link
Member

Fixes #21403.

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::
Copy link
Member

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.

Copy link
Member Author

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.

{
$uuid = $this->uuidFactory->create();

$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */);
Copy link
Member

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:

Suggested change
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */);
$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */)->create();

Copy link
Member

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)


$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */);
$randomBasedUuid = $this->uuidFactory->randomBased();
$timestampBased = $this->uuidFactory->timeBased();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$timestampBased = $this->uuidFactory->timeBased();
$timestampBased = $this->uuidFactory->timeBased()->create();

$uuid = $this->uuidFactory->create();

$nameBasedUuid = $this->uuidFactory->nameBased(/** ... */);
$randomBasedUuid = $this->uuidFactory->randomBased();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$randomBasedUuid = $this->uuidFactory->randomBased();
$randomBasedUuid = $this->uuidFactory->randomBased()->create();

}
}
Starting from Symfony 7.4, the default version for both UUIDs and time-based
UUIDs is UUIDv7. In previous versions, the default was UUIDv6.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UUIDs is UUIDv7. In previous versions, the default was UUIDv6.
UUIDs is v7. In previous versions, the default was v6.

@javiereguiluz
Copy link
Member Author

Thanks for the review, folks! I made some changes.


$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();
Copy link
Member

@xabbuh xabbuh Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$nameBasedUuid = $this->uuidFactory->nameBased($namespace)->create();
$nameBasedUuid = $this->uuidFactory->nameBased($namespace)->create($name);

Copy link
Member Author

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!

@javiereguiluz javiereguiluz merged commit 1fc2ba1 into symfony:7.4 Sep 26, 2025
3 checks passed
@javiereguiluz javiereguiluz deleted the fix_21403 branch October 3, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants