Skip to content

Commit 0581165

Browse files
committed
feature #20127 [Uid] Add support for binary, base-32 and base-58 representations in Uuid::isValid() (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- [Uid] Add support for binary, base-32 and base-58 representations in `Uuid::isValid()` Fix #20111 Commits ------- 8d5b1d3 [Uid] Add support for binary, base-32 and base-58 representations in `Uuid::isValid()`
2 parents c909000 + 8d5b1d3 commit 0581165

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

components/uid.rst

+24
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,30 @@ UUID objects created with the ``Uuid`` class can use the following methods
314314
// * int < 0 if $uuid1 is less than $uuid4
315315
$uuid1->compare($uuid4); // e.g. int(4)
316316

317+
If you're working with different UUIDs format and want to validate them,
318+
you can use the ``$format`` parameter of the :method:`Symfony\\Component\\Uid\\Uuid::isValid`
319+
method to specify the UUID format you're expecting::
320+
321+
use Symfony\Component\Uid\Uuid;
322+
323+
$isValid = Uuid::isValid('90067ce4-f083-47d2-a0f4-c47359de0f97', Uuid::FORMAT_RFC_4122); // accept only RFC 4122 UUIDs
324+
$isValid = Uuid::isValid('3aJ7CNpDMfXPZrCsn4Cgey', Uuid::FORMAT_BASE_32 | Uuid::FORMAT_BASE_58); // accept multiple formats
325+
326+
The following constants are available:
327+
328+
* ``Uuid::FORMAT_BINARY``
329+
* ``Uuid::FORMAT_BASE_32``
330+
* ``Uuid::FORMAT_BASE_58``
331+
* ``Uuid::FORMAT_RFC_4122``
332+
333+
You can also use the ``Uuid::FORMAT_ALL`` constant to accept any UUID format.
334+
By default, only the RFC 4122 format is accepted.
335+
336+
.. versionadded:: 7.2
337+
338+
The ``$format`` parameter of the :method:`Symfony\\Component\\Uid\\Uuid::isValid`
339+
method and the related constants were introduced in Symfony 7.2.
340+
317341
Storing UUIDs in Databases
318342
~~~~~~~~~~~~~~~~~~~~~~~~~~
319343

0 commit comments

Comments
 (0)