Symfony UID

Object-oriented PHP API to generate, parse, and represent UUIDs and ULIDs.

Library
Composer
vv8.1.4
607stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity76
Maintenance80
Community56
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
86/100Excellent
Architecture88
Code Quality90
Innovation80
Learning Curve85

Symfony UID is a standalone PHP component that provides a clean, object-oriented API for working with unique identifiers. It supports ULIDs and UUID versions 1 and 3 through 8, wrapping each identifier type in an immutable value object with methods for conversion between binary, RFC 4122, Base32, and Base58 representations.

Beyond raw generation, the component ships dedicated factories, name-based and time-based UUID helpers, a mock factory for deterministic tests, and CLI commands to generate and inspect identifiers. It runs on both 32-bit and 64-bit CPUs and integrates cleanly with the wider Symfony ecosystem while remaining usable in any PHP project.

What You Get

  • Immutable value objects for ULIDs and UUID versions 1 and 3 through 8
  • Factories for random, time-based, name-based, and mock identifier generation
  • Conversion between binary, RFC 4122, Base32, and Base58 encodings
  • CLI commands to generate and inspect UIDs from the terminal
  • 32-bit and 64-bit CPU support with no native extension required

Common Use Cases

  • Generating sortable ULIDs or UUIDv7 primary keys for database records
  • Producing deterministic name-based UUIDs (v3/v5) from namespaces
  • Creating opaque, URL-safe identifiers for public-facing resources

Under The Hood

Architecture - The component centers on an AbstractUid base class that both Uuid and Ulid extend, storing the identifier as a normalized internal string and exposing shared comparison, encoding, and equality behavior. Concrete UUID versions (UuidV1, UuidV4, UuidV7, etc.) subclass Uuid, each pinning a TYPE constant and validating the version nibble in its constructor, while dedicated Factory classes encapsulate each generation strategy (random, time-based, name-based, mock) so construction logic stays separate from the value objects. BinaryUtil handles the low-level bit manipulation shared across encodings.

Tech Stack - Pure PHP targeting modern versions (composer requires php >=8.4.1), with symfony/polyfill-uuid as its only runtime dependency and symfony/console as an optional dev dependency powering the CLI commands. It uses PSR-4 autoloading under the Symfony\Component\Uid namespace and PHPUnit for its test suite; no native C extension is required.

Code Quality - The codebase is idiomatic Symfony: small focused classes, strict input validation with typed exceptions, and consistent RFC references in docblocks. A Tests/ directory covers ULID, UUID, transformer, factory, and command behavior, and identifier parsing is guarded by precise regular expressions and variant checks that throw InvalidArgumentException on malformed input.

API Design - The public surface is deliberately ergonomic: static constructors like Uuid::v4(), Ulid::fromString(), and format accessors (toBase32(), toBinary(), toRfc4122()) read naturally and require almost no boilerplate. Format flags are exposed as class constants, and the factory objects give applications a testable seam for dependency injection, matching conventions developers already know from the broader Symfony ecosystem.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search