Search by

Named ID generators for UUIDs, ULIDs, Snowflake, and compact public IDs for Switon Framework

v1.0.2 2026-08-22 14:37 UTC

This package is auto-updated.

Last update: 2026-11-24 13:24:13 UTC


README

CI PHP 8.3+

Switon's ID generation package for interface-first services that need selectable strategies, sortable identifiers, and compact public IDs.

Highlights

  • Pluggable ID generation: IdGeneratorInterface can be swapped as needed.
  • Named ID strategies: common strategies are ready to use through the service provider.
  • Distributed Snowflake support: sequence allocation can be coordinated through Redis.
  • Time-ordered identifiers: Uuid7, Ulid, and Ksuid produce sortable string IDs.
  • Compact formats: NanoId, Cuid2, ShortUuid, and MongoId cover shorter public IDs.

Installation

composer require switon/id

Quick Start

use Switon\Core\Attribute\Autowired;
use Switon\Id\IdGeneratorInterface;

class OrderService
{
    #[Autowired] protected IdGeneratorInterface $idGenerator;

    public function createOrder(): string
    {
        return (string) $this->idGenerator->next();
    }
}

Docs: https://github.com/switon-php/id/blob/main/docs/README.md

License

MIT.