@@ -370,6 +370,116 @@ of the ULID parameters::
370
370
}
371
371
}
372
372
373
+ Generating and Inspecting UUIDs/ULIDs in the Console
374
+ ----------------------------------------------------
375
+
376
+ .. versionadded :: 5.3
377
+
378
+ The commands to inspect and generate UUIDs/ULIDs were introduced in Symfony 5.3.
379
+
380
+ This component provides several commands to generate and inspect UUIDs/ULIDs in
381
+ the console. They are not enabled by default, so you must add the following
382
+ configuration in your application before using these commands:
383
+
384
+ .. configuration-block ::
385
+
386
+ .. code-block :: yaml
387
+
388
+ # config/services.yaml
389
+ services :
390
+ Symfony\Component\Uid\Command\GenerateUlidCommand : ~
391
+ Symfony\Component\Uid\Command\GenerateUuidCommand : ~
392
+ Symfony\Component\Uid\Command\InspectUlidCommand : ~
393
+ Symfony\Component\Uid\Command\InspectUuidCommand : ~
394
+
395
+ .. code-block :: xml
396
+
397
+ <!-- config/services.xml -->
398
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
399
+ <container xmlns =" http://symfony.com/schema/dic/services"
400
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
401
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
402
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
403
+
404
+ <services >
405
+ <!-- ... -->
406
+
407
+ <service id =" Symfony\Component\Uid\Command\GenerateUlidCommand" />
408
+ <service id =" Symfony\Component\Uid\Command\GenerateUuidCommand" />
409
+ <service id =" Symfony\Component\Uid\Command\InspectUlidCommand" />
410
+ <service id =" Symfony\Component\Uid\Command\InspectUuidCommand" />
411
+ </services >
412
+ </container >
413
+
414
+ .. code-block :: php
415
+
416
+ // config/services.php
417
+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
418
+
419
+ use Symfony\Component\Uid\Command\GenerateUlidCommand;
420
+ use Symfony\Component\Uid\Command\GenerateUuidCommand;
421
+ use Symfony\Component\Uid\Command\InspectUlidCommand;
422
+ use Symfony\Component\Uid\Command\InspectUuidCommand;
423
+
424
+ return static function (ContainerConfigurator $configurator): void {
425
+ // ...
426
+
427
+ $services
428
+ ->set(GenerateUlidCommand::class)
429
+ ->set(GenerateUuidCommand::class)
430
+ ->set(InspectUlidCommand::class)
431
+ ->set(InspectUuidCommand::class);
432
+ };
433
+
434
+ Now you can generate UUIDs/ULIDs as follows (add the ``--help `` option to the
435
+ commands to learn about all their options):
436
+
437
+ .. code-block :: terminal
438
+
439
+ # generate 1 random-based UUID
440
+ $ php bin/console uuid:generate --random-based
441
+
442
+ # generate 1 time-based UUID with a specific node
443
+ $ php bin/console uuid:generate --time-based=now --node=fb3502dc-137e-4849-8886-ac90d07f64a7
444
+
445
+ # generate 2 UUIDs and output them in base58 format
446
+ $ php bin/console uuid:generate --count=2 --format=base58
447
+
448
+ # generate 1 ULID with the current time as the timestamp
449
+ $ php bin/console ulid:generate
450
+
451
+ # generate 1 ULID with a specific timestamp
452
+ $ php bin/console ulid:generate --time="2021-02-02 14:00:00"
453
+
454
+ # generate 2 ULIDs and ouput them in RFC4122 format
455
+ $ php bin/console ulid:generate --count=2 --format=rfc4122
456
+
457
+ In addition to generating new UIDs, you can also inspect them with the following
458
+ commands to show all the information for a given UID:
459
+
460
+ .. code-block :: terminal
461
+
462
+ $ php bin/console uuid:inspect d0a3a023-f515-4fe0-915c-575e63693998
463
+ ---------------------- --------------------------------------
464
+ Label Value
465
+ ---------------------- --------------------------------------
466
+ Version 4
467
+ Canonical (RFC 4122) d0a3a023-f515-4fe0-915c-575e63693998
468
+ Base 58 SmHvuofV4GCF7QW543rDD9
469
+ Base 32 6GMEG27X8N9ZG92Q2QBSHPJECR
470
+ ---------------------- --------------------------------------
471
+
472
+ $ php bin/console ulid:inspect 01F2TTCSYK1PDRH73Z41BN1C4X
473
+ --------------------- --------------------------------------
474
+ Label Value
475
+ --------------------- --------------------------------------
476
+ Canonical (Base 32) 01F2TTCSYK1PDRH73Z41BN1C4X
477
+ Base 58 1BYGm16jS4kX3VYCysKKq6
478
+ RFC 4122 0178b5a6-67d3-0d9b-889c-7f205750b09d
479
+ --------------------- --------------------------------------
480
+ Timestamp 2021-04-09 08:01:24.947
481
+ --------------------- --------------------------------------
482
+
373
483
.. _`unique identifiers` : https://en.wikipedia.org/wiki/UID
374
484
.. _`UUIDs` : https://en.wikipedia.org/wiki/Universally_unique_identifier
375
485
.. _`ULIDs` : https://github.com/ulid/spec
0 commit comments