Switon's ID generation package for interface-first services that need selectable strategies, sortable identifiers, and compact public IDs.
- Pluggable ID generation:
IdGeneratorInterfacecan 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, andKsuidproduce sortable string IDs. - Compact formats:
NanoId,Cuid2,ShortUuid, andMongoIdcover shorter public IDs.
composer require switon/iduse 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
MIT.