UUID Library (and ULID to UUID migration) ######################################### :date: 2023-07-14 05:48:00 +0300 :category: PHP :tags: uuid, ulid I created `a UUID and ULID library `__ with `Doctrine support `__. Well, who didn't :D .. _lib: https://sandfox.dev/php/uuid.html .. _doctrine: https://sandfox.dev/php/uuid/doctrine.html The main scenario for myself was a possible migration for a project from ULIDs to UUIDs since UUIDs got a little bit of support in MySQL 8. .. warning:: The conversion is lossy (of a few bits), if you want to do the same, first run a simulation that you won't get collisions. (You shouldn't if the generation was random enough but who knows) Example code: .. code-block:: php isUuidV7Compatible()); // false // UnexpectedValueException: This ULID cannot be converted to UUID v7 losslessly // $uuid = $ulid->toUuidV7(); $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->toRfc4122()); // 01890986-fbb2-b3d8-f424-b51ad7d67f0c var_dump($uuid->toBase32()); // 01H44RDYXJEFCB895N3BBXCZRC var_dump($ulid->toString()); // 01H44RDYXJPFCF895N3BBXCZRC