| 123456789101112131415161718192021 |
- <?php
- namespace App\Service\Utils;
- class Uuid
- {
- /**
- * Generates an UUID v4.
- *
- * @param ?int $length To limit the length of the uuid (standard uuid count 36 cars). Warning: reducing
- * the number of characters breaks the warranty of global unity.
- *
- * @throws \Exception
- */
- public static function uuid(?int $length = null): string
- {
- $uuid = \Ramsey\Uuid\Uuid::uuid4()->toString();
- return $length !== null ? substr($uuid, 0, $length) : $uuid;
- }
- }
|