subiabre / doctrine-snowflakes
Custom id generator implementing snowflake algorithm
Installs: 237
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/subiabre/doctrine-snowflakes
Requires
- doctrine/orm: ^2.16
- godruoyi/php-snowflake: ^3.0
Requires (Dev)
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2025-09-24 01:46:16 UTC
README
ID Generator for Doctrine implementing the Snowflake algorithm.
Install
$ composer require subiabre/doctrine-snowflakes
Usage
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
Testing
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