ID Generator for Doctrine implementing the Snowflake algorithm.
$ composer require subiabre/doctrine-snowflakes
In your entity classes:
#[ORM\Id()]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: SnowflakeGenerator::class)]
#[ORM\Column(type: Types::BIGINT]
private string $id;
Take in consideration that PHP does not have a proper bigint
data type. Due to this limitation, doctrine-snowflake IDs should be used as string
.
public function getId(): string
This package includes unit tests with the PHPUnit library. Run the tests with:
./vendor/bin/phpunit
The default test cases test against concurrency and uniqueness in 10 batches of 300 IDs each batch, alternatively you can supply any batch size with:
BATCH_SIZE=1000 ./vendor/bin/phpunit