New in Symfony 6.2: New Uid Features

The Uid component provides an object-oriented API to generate and represent UIDs such as UUID and ULID. In Symfony 6.2 we're adding some features to it.

MaxUuid and MaxUlid

Contributed by
Nicolas Grekas
in #47515.

In Symfony 6.2 we're introducing two new classes called MaxUlid and MaxUuid which represent the highest possible value of both UUID and ULID. You can use those objects to get the max values string representation, to compare them to other UID objects, etc.

If you are curious, these are the maximum values possible:

Max UUID: 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'
Max ULID: '7ZZZZZZZZZZZZZZZZZZZZZZZZZ'

Time-based Uid Interface

Contributed by
Barney Hanlon
in #47507.

Some UIDs include a date/time as part of their value. In Symfony 6.2 we're introducing the following interface so you can get this date/time value more easily:

interface TimeBasedUidInterface
{
    public function getDateTime(): \DateTimeImmutable;
}

The interface is only implemented by the UID types/versions that include a date/time, which are: Ulid, UuidV1, and UuidV6.

Uid Conversion to Hexadecimal Values

Contributed by
Aurimas Niekis
in #45945.

UIDs include lots of methods to convert their value into different formats (toBase32(), toBase58(), toRfc4122(), etc.) In Symfony 6.2 we're introducing a new toHex() method which returns the binary value as an hexadecimal string:

use Symfony\Component\Uid\Uuid;

$uuid = Uuid::v4()
// e.g. (string) $uuid = 'd6b3345b-2905-4048-a83c-b5988e765d98'
$hex = $uuid->toHex();
// $hex = '0xd6b3345b29054048a83cb5988e765d98'

The hexadecimal string returned by toHex() is ready to use in other parts of your application, such as storing or querying UIDs in binary format in the database.

UuidV7 and UuidV8 Support

Contributed by
Nicolas Grekas
in #47525.

The UUID specification continues adding new formats to generate values suited for different scenarios. They recently added UUID Version 7 and UUID Version 8 formats and Symfony 6.2 adds support for them:

use Symfony\Component\Uid\Uuid;

$uuid = Uuid::v7();
// e.g. (string) $uuid = '017f22e2-79b0-7cc3-98c4-dc0c0c07398f'
$uuid = Uuid::v8();
// e.g. (string) $uuid = '216fff40-98d9-81e3-a5e2-0800200c9a66'

Conceptually, UUID v7 is very similar to ULID: they're monotonic, sortable, unguessable, and embed a ms-unix-timestamp.

            <hr style="margin-bottom: 5px" />
            <div style="font-size: 90%">
                <a href="https://symfony.com/sponsor">Sponsor</a> the Symfony project.
            </div>

https://symfony.com/blog/new-in-symfony-6-2-new-uid-features?utm_source=Symfony%20Blog%20Feed&utm_medium=feed

Created 3y | Nov 17, 2022, 5:20:14 PM


Login to add comment

Other posts in this group

SymfonyOnline June 2025: Speakers, Stats & Replays!

Thank you for joining us at SymfonyOnline June 2025!

What a great edition of SymfonyOnline we’ve just wrapped up! 🎉

We were thrilled to welcome 300 participants from 35 different countries—a

Jun 18, 2025, 8:50:17 AM | Symfony
A Week of Symfony #963 (June 9–15, 2025)

This week, Symfony celebrated the SymfonyOnline June 2025 conference with great success. Meanwhile, development efforts focused on improving invokable commands for the upcoming Symfony 7.4 version. Th

Jun 15, 2025, 9:10:09 AM | Symfony
A Week of Symfony #962 (June 2–8, 2025)

This week, development activity focused on the upcoming Symfony 7.4 and 8.0 versions, which will deprecate and remove many features. In addition, we published a case study about Yousign. Finally, we'r

Jun 8, 2025, 7:50:05 AM | Symfony
Case study - Yousign: Scaling Trust with Smart, Scalable Architecture

As digital signatures become the norm in modern business, Yousign has established itself as a trusted leader across Europe. Behind its simple, intuitive interface is a powerful technical engine, handl

Jun 6, 2025, 7:10:24 AM | Symfony
SymfonyOnline June 2025 starts next week!

Get ready for the exciting SymfonyOnline June 2025, kicking off in a few days only! There’s still time to register and join the international online Symfony conference—along with pre-conferenc

Jun 5, 2025, 10:20:09 AM | Symfony
A Week of Symfony #961 (May 26 – June 1, 2025)

This week, Symfony released the stable version of Symfony 7.3, which includes lots of amazing new features. We also published the maintenance versions 6.4.22 and 7.2.7.

Symfony development highlights

Jun 1, 2025, 8:50:16 AM | Symfony
New in Symfony 7.3: DX Improvements (part 2)

This is the second part of the blog post showcasing the main DX (developer experience) features introduced in Symfony 7.3. Read the first part of this blog post.

Verify URI Signatures… https://symfon

May 29, 2025, 9:10:19 AM | Symfony