Skip to content

Repository files navigation

Switon ID Package

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.

About

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

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages