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

Maintainers

Package info

github.com/switon-php/id

Documentation

pkg:composer/switon/id

Statistics

Installs: 25

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 04:34:02 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://docs.switon.dev/latest/id

License

MIT.