UUID Versions ############# .. highlight:: php Special ======= Nil UUID -------- ``Arokettu\Uuid\NilUuid`` ``{00000000-0000-0000-0000-000000000000}`` Nil UUID as described in the `RFC 9562`_. The class can be constructed directly, its constructor does not accept any parameters. Max UUID -------- ``Arokettu\Uuid\MaxUuid`` ``{ffffffff-ffff-ffff-ffff-ffffffffffff}`` Max UUID as described in the `RFC 9562`_. The class can be constructed directly, its constructor does not accept any parameters. Generic UUID ------------ ``Arokettu\Uuid\GenericUuid`` Any UUID that is not Nil, Max or Variant10xx and is not marked as ULID will be parsed to this class. The class can also be initialized directly with any 32 hexadecimal digits. (Obviously, the class will not be cast to a version class in case the data happen to be a valid version or special UUID) RFC 9562 ======== Variant 10xx versions described in `RFC 9562`_. Any class can be initialized directly by 32 hexadecimal digits but the correct variant and version bits must be set. Version 1 --------- ``Arokettu\Uuid\UuidV1``. The class implements ``TimeBasedUuid`` interface. UUIDv1 timestamp is measured to 100 nsec precision which is more than DateTime can handle therefore the returned value will be truncated by one decimal. The range is ``1582-10-15 00:00:00.0 +00:00`` -- ``5236-03-31 21:21:00.684697 +00:00``. UUIDv1 can be rearranged without loss of any data and precision into a lexicographically monotonic UUIDv6. Use the ``toUuidV6()`` method for that:: toUuidV6(); var_dump($uuid6->toString()); // 1d19dad6-ba7b-6811-80b4-00c04fd430c8 Version 2 --------- .. versionadded:: 2.3 ``getDomain()`` and ``getIdentifier()`` ``Arokettu\Uuid\UuidV2``. "DCE security" legacy UUID. Preferably they should never be used. The class implements ``TimeBasedUuid`` interface with 429'496'729'600 nsec precision (approximately 7 minutes) due to truncated timestamp field compared to V1. The range is ``1582-10-15 00:00:00.0 +00:00`` -- ``5236-03-31 21:13:51.187968 +00:00``. The library allows you to retrieve domain and identifier values:: getDomain()); // 0 var_dump($uuid->getIdentifier()); // 1234 .. warning:: Identifier is an unsigned 32-bit value, it is possible to get an overflow error on a 32-bit system. Version 3 --------- ``Arokettu\Uuid\UuidV3``. MD5 based namespace UUID. Version 4 --------- ``Arokettu\Uuid\UuidV4``. Random UUID. This is the recommended version if you don't need monotonicity. Version 5 --------- ``Arokettu\Uuid\UuidV5``. SHA1 based namespace UUID. Version 6 --------- ``Arokettu\Uuid\UuidV6``. Basically a rearrangement of UUIDv1 fields. They are mostly useful as a conversion from UUIDv1. The class implements ``TimeBasedUuid`` interface. UUIDv1 timestamp is measured to 100 nsec precision which is more than DateTime can handle therefore the returned value will be truncated by one decimal. The range is ``1582-10-15 00:00:00.0 +00:00`` -- ``5236-03-31 21:21:00.684697 +00:00``. UUIDv6 can be rearranged without loss of any data and precision into a legacy UUIDv1. Use the ``toUuidV1()`` method for that:: toUuidV1(); var_dump($uuid1->toString()); // 6ba7b811-9dad-11d1-80b4-00c04fd430c8 Version 7 --------- ``Arokettu\Uuid\UuidV7``. A lexicographically monotonic version. This is the recommended version if you do need monotonicity. UUIDv7 was designed after ULID and shares the timestamp structure with it. The class implements ``TimeBasedUuid`` interface with millisecond precision in range ``1970-01-01 00:00:00 +00:00`` -- ``10889-08-02 05:31:50.655 +00:00``. UUIDv7 without any bit change can be converted to a ULID. Use ``toUlid()`` for that:: toUlid(); var_dump($ulid->toString()); // 01H44Q8TJ8EP0B9GNZKB6YF4J0 var_dump($ulid->toRfcFormat()); // 01890974-6a48-7580-b4c2-bf9acde79240 Version 8 --------- ``Arokettu\Uuid\UuidV8``. This is a special version for custom UUIDs. The class can be extended:: isUuidV7Compatible()); // true $uuid = $ulid->toUuidV7(); var_dump($uuid->toString()); // 01890974-6a48-7580-b4c2-bf9acde79240 var_dump($uuid->toBase32()); // 01H44Q8TJ8EP0B9GNZKB6YF4J0 // Just a random ULID $ulid = UuidParser::fromBase32('01H44RDYXJPFCF895N3BBXCZRC'); var_dump($ulid->isUuidV7Compatible()); // false // $uuid = $ulid->toUuidV7(); // UnexpectedValueException: This ULID cannot be converted to UUID v7 losslessly $uuid = $ulid->toUuidV7(lossy: true); // note digit 13 becoming '7' and digit 17 moving into [89ab] range var_dump($uuid->toString()); // 01890986-fbb2-73d8-b424-b51ad7d67f0c var_dump($ulid->toRfcFormat()); // 01890986-fbb2-b3d8-f424-b51ad7d67f0c var_dump($uuid->toBase32()); // 01H44RDYXJEFCB895N3BBXCZRC var_dump($ulid->toString()); // 01H44RDYXJPFCF895N3BBXCZRC .. _RFC 9562: https://datatracker.ietf.org/doc/html/rfc9562 .. _ULID spec: https://github.com/ulid/spec