UUID Library (and ULID to UUID migration)

I created a UUID and ULID library with Doctrine support. Well, who didn't :D

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.

Example code:

<?php

use Arokettu\Uuid\UuidParser;

// Just a random ULID
$ulid = UuidParser::fromBase32('01H44RDYXJPFCF895N3BBXCZRC');
var_dump($ulid->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

Comments

Comments powered by Disqus