infocyph / uid
UUID (RFC 9562), ULID, Snowflake ID, Sonyflake ID, and TBSL generator for PHP.
3.0.2
2025-12-17 11:28 UTC
Requires
- php: >=8.0
- ext-bcmath: *
Requires (Dev)
- captainhook/captainhook: ^5.24
- laravel/pint: ^1.20
- pestphp/pest: ^3.7
- rector/rector: ^2.0
- symfony/var-dumper: ^7.2
Replaces
README
All-in-one unique ID toolkit for PHP.
Features
- UUID (
v1,v3,v4,v5,v6,v7,v8) - ULID (monotonic and random modes)
- Snowflake, Sonyflake, TBSL
- NanoID, CUID2, KSUID, XID
- Opaque and deterministic IDs
- Value objects and comparator utilities
- Binary conversion and base encoders (
16,32,36,58,62) - Pluggable sequence providers (filesystem, memory, PSR-16 cache, callback)
Requirements
- PHP
>=8.2 ext-bcmath
Installation
composer require infocyph/uid
Global helper functions are autoloaded via src/functions.php.
Quick Usage
<?php use Infocyph\UID\Id; $uuid = Id::uuid(); // default UUID strategy (v7) $ulid = Id::ulid(); $snowflake = Id::snowflake(); $sonyflake = Id::sonyflake(); $tbsl = Id::tbsl(); $nanoid = Id::nanoId(21); $cuid2 = Id::cuid2(24);
<?php use Infocyph\UID\UUID; $uuid = UUID::v7(); $ok = UUID::isValid($uuid); $parsed = UUID::parse($uuid); $bytes = UUID::toBytes($uuid); $roundTrip = UUID::fromBytes($bytes); $base58 = UUID::toBase($uuid, 58); $decoded = UUID::fromBase($base58, 58);
References
- UUID: https://datatracker.ietf.org/doc/html/rfc9562
- ULID: https://github.com/ulid/spec
- Snowflake: https://github.com/twitter-archive/snowflake/tree/snowflake-2010
- Sonyflake: https://github.com/sony/sonyflake
- NanoID: https://github.com/ai/nanoid
- CUID2: https://github.com/paralleldrive/cuid2
- TBSL note: https://github.com/infocyph/UID/blob/main/TBSL.md