Skip to content

[Uid] Add support for binary, base-32 and base-58 representations in Uuid::isValid() #20127

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

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions components/uid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,30 @@ UUID objects created with the ``Uuid`` class can use the following methods
// * int < 0 if $uuid1 is less than $uuid4
$uuid1->compare($uuid4); // e.g. int(4)

If you're working with different UUIDs format and want to validate them,
you can use the ``$format`` parameter of the :method:`Symfony\\Component\\Uid\\Uuid::isValid`
method to specify the UUID format you're expecting::

use Symfony\Component\Uid\Uuid;

$isValid = Uuid::isValid('90067ce4-f083-47d2-a0f4-c47359de0f97', Uuid::FORMAT_RFC_4122); // accept only RFC 4122 UUIDs
$isValid = Uuid::isValid('3aJ7CNpDMfXPZrCsn4Cgey', Uuid::FORMAT_BASE_32 | Uuid::FORMAT_BASE_58); // accept multiple formats

The following constants are available:

* ``Uuid::FORMAT_BINARY``
* ``Uuid::FORMAT_BASE_32``
* ``Uuid::FORMAT_BASE_58``
* ``Uuid::FORMAT_RFC_4122``

You can also use the ``Uuid::FORMAT_ALL`` constant to accept any UUID format.
By default, only the RFC 4122 format is accepted.

.. versionadded:: 7.2

The ``$format`` parameter of the :method:`Symfony\\Component\\Uid\\Uuid::isValid`
method and the related constants were introduced in Symfony 7.2.

Storing UUIDs in Databases
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
Loading