Uuid.php 515 B

12345678910111213141516171819
  1. <?php
  2. namespace App\Service\Utils;
  3. class Uuid
  4. {
  5. /**
  6. * Generates an UUID v4
  7. *
  8. * @var ?int $length To limit the length of the uuid (standard uuid count 36 cars). Warning: reducing
  9. * the number of characters breaks the warranty of global unity.
  10. * @return string
  11. */
  12. public static function uuid(int $length = null): string
  13. {
  14. $uuid = \Ramsey\Uuid\Uuid::uuid4()->toString();
  15. return $length !== null ? substr($uuid, 0, $length) : $uuid;
  16. }
  17. }