Small Id Generator

I wanted a php library with no composer dependencies to generate unique id, and I finally wrote this : small/id

A tiny PHP library that provides a uniform interface to generate a variety of unique identifiers:
UUID (v1/2/3/4/5/6/7), ULID, KSUID, Snowf…


This content originally appeared on DEV Community and was authored by sebk69

I wanted a php library with no composer dependencies to generate unique id, and I finally wrote this : small/id

A tiny PHP library that provides a uniform interface to generate a variety of unique identifiers:
UUID (v1/2/3/4/5/6/7), ULID, KSUID, Snowflake, ObjectId, and NanoID — via a simple IdInterface and a factory.

use Small\Id\IdFactory;
use Small\Id\Enum\IdType;

$factory = new IdFactory();

$uuid7 = $factory->getId(IdType::uuid_v7)->generate();   // e.g. "018fb27a-a2b1-7c3d-8e9f-1a2b3c4d5e6f"
$ulid  = $factory->getId(IdType::ulid)->generate();      // e.g. "01J234ABCD3EFG4567HJKMNPRT"
$ksuid = $factory->getId(IdType::ksuid)->generate();     // base62 string (~27 chars)
$snow  = $factory->getId(IdType::snowflacke)->generate();// decimal string (64‑bit composed)
$oid   = $factory->getId(IdType::objectid)->generate();  // 24‑hex Mongo‑like
$nano  = $factory->getId(IdType::nanoid)->generate();    // 21 chars URL‑safe

Get it

composer require small/id

git : https://git.small-project.dev/lib/small-id
packagist : https://packagist.org/packages/small/id


This content originally appeared on DEV Community and was authored by sebk69


Print Share Comment Cite Upload Translate Updates
APA

sebk69 | Sciencx (2025-10-04T20:31:35+00:00) Small Id Generator. Retrieved from https://www.scien.cx/2025/10/04/small-id-generator/

MLA
" » Small Id Generator." sebk69 | Sciencx - Saturday October 4, 2025, https://www.scien.cx/2025/10/04/small-id-generator/
HARVARD
sebk69 | Sciencx Saturday October 4, 2025 » Small Id Generator., viewed ,<https://www.scien.cx/2025/10/04/small-id-generator/>
VANCOUVER
sebk69 | Sciencx - » Small Id Generator. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/10/04/small-id-generator/
CHICAGO
" » Small Id Generator." sebk69 | Sciencx - Accessed . https://www.scien.cx/2025/10/04/small-id-generator/
IEEE
" » Small Id Generator." sebk69 | Sciencx [Online]. Available: https://www.scien.cx/2025/10/04/small-id-generator/. [Accessed: ]
rf:citation
» Small Id Generator | sebk69 | Sciencx | https://www.scien.cx/2025/10/04/small-id-generator/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.