Download the PHP package tourze/doctrine-snowflake-bundle without Composer
On this page you can find all versions of the php package tourze/doctrine-snowflake-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/doctrine-snowflake-bundle
More information about tourze/doctrine-snowflake-bundle
Files in tourze/doctrine-snowflake-bundle
Package doctrine-snowflake-bundle
Short Description 为 Doctrine 实体提供雪花ID自动生成功能
License MIT
Informations about the package doctrine-snowflake-bundle
Doctrine Snowflake Bundle
A Symfony bundle that provides Snowflake ID generation for Doctrine entities with distributed unique ID generation capabilities.
中文
Table of Contents
- Features
- Requirements
- Installation
- Configuration
- Bundle Registration
- Quick Start
- Method 1: Using SnowflakeKeyAware Trait (Recommended)
- Method 2: Using SnowflakeColumn Attribute
- Method 3: Manual ID Generator Configuration
- Advanced Usage
- Custom Configuration
- Multiple Snowflake Properties
- Performance Tuning
- API Reference
- SnowflakeColumn Attribute
- SnowflakeKeyAware Trait
- SnowflakeIdGenerator Service
- Testing
- Performance Considerations
- Contributing
- License
- Changelog
Features
- Snowflake ID Generation: Based on godruoyi/php-snowflake
- Doctrine Integration: Auto-generate Snowflake IDs for Doctrine entity primary keys
- Attribute Support: Use
#[SnowflakeColumn]attribute for custom ID properties - Trait Support: Use
SnowflakeKeyAwaretrait for automatic primary key generation - Distributed Ready: WorkerId auto-generated by hostname, supporting distributed deployment
- Data Center ID: Automatically generated from entity class name for better ID distribution
- String Format: Returns IDs as strings to avoid JavaScript precision issues
- High Performance: Optimized for high concurrency scenarios
Requirements
- PHP 8.1 or newer
- Symfony 7.3 or newer
- Doctrine Bundle 2.13 or newer
- Doctrine ORM 3.0 or newer
- Doctrine DBAL 4.0 or newer
- tourze/symfony-snowflake-bundle
Installation
Configuration
Bundle Registration
The bundle is automatically registered when using Symfony Flex. For manual installation:
Quick Start
Method 1: Using SnowflakeKeyAware Trait (Recommended)
For primary key generation:
Method 2: Using SnowflakeColumn Attribute
For custom ID properties (not primary keys):
Method 3: Manual ID Generator Configuration
Advanced Usage
Custom Configuration
You can customize the Snowflake ID generation behavior:
Multiple Snowflake Properties
You can use multiple Snowflake properties in a single entity:
Performance Tuning
For high-throughput applications:
- Use appropriate database indexes on Snowflake ID columns
- Consider using string column types to avoid integer overflow
- Monitor ID generation performance in distributed environments
API Reference
SnowflakeColumn Attribute
prefix: ID prefix (default: empty)length: Maximum ID length (default: 0, no limit)
SnowflakeKeyAware Trait
Provides the following methods:
getId(): ?string- Get the entity IDsetId(?string $id): void- Set the entity ID
SnowflakeIdGenerator Service
- Automatically generates unique Snowflake IDs
- Uses hostname for worker ID generation
- Uses entity class name for data center ID generation
- Preserves existing IDs when set manually
Testing
Run the test suite:
Performance Considerations
- Snowflake IDs are returned as strings to avoid JavaScript precision issues
- The generator uses CRC32 hash of class names for data center ID distribution
- Worker ID is generated from hostname for distributed deployments
- High concurrency scenarios are handled efficiently
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
The MIT License (MIT). Please see License File for more information.
Changelog
See Releases for version history.
All versions of doctrine-snowflake-bundle with dependencies
doctrine/common Version ^3.5
doctrine/dbal Version ^4.0
doctrine/doctrine-bundle Version ^2.13
doctrine/orm Version ^3.0
doctrine/persistence Version ^4.1
monolog/monolog Version ^3.1
psr/log Version ^3|^2|^1
symfony/config Version ^7.3
symfony/console Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/doctrine-bridge Version ^7.3
symfony/event-dispatcher Version ^7.3
symfony/expression-language Version ^7.3
symfony/framework-bundle Version ^7.3
symfony/http-foundation Version ^7.3
symfony/http-kernel Version ^7.3
symfony/lock Version ^7.3
symfony/messenger Version ^7.3
symfony/property-access Version ^7.3
symfony/string Version ^7.3
symfony/yaml Version ^7.3
tourze/bundle-dependency Version 1.*
tourze/doctrine-entity-checker-bundle Version 1.0.*
tourze/symfony-dependency-service-loader Version 1.0.*
tourze/symfony-snowflake-bundle Version 1.0.*