tourze / doctrine-uuid-bundle
Symfony bundle for automatic UUID (v1/v4) assignment in Doctrine entities using PHP 8 attributes
Installs: 23
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/tourze/doctrine-uuid-bundle
Requires
- doctrine/dbal: ^4.0
 - doctrine/doctrine-bundle: ^2.13
 - doctrine/orm: ^3.0
 - doctrine/persistence: ^4.1
 - monolog/monolog: ^3.1
 - psr/log: ^3|^2|^1
 - symfony/config: ^7.3
 - symfony/dependency-injection: ^7.3
 - symfony/doctrine-bridge: ^7.3
 - symfony/framework-bundle: ^7.3
 - symfony/http-kernel: ^7.3
 - symfony/property-access: ^7.3
 - symfony/uid: ^7.3
 - symfony/yaml: ^7.3
 - tourze/bundle-dependency: 1.*
 - tourze/doctrine-entity-checker-bundle: 1.0.*
 - tourze/symfony-dependency-service-loader: 1.*
 
Requires (Dev)
- phpstan/phpstan: ^2.1
 - phpunit/phpunit: ^11.5
 - tourze/phpunit-symfony-kernel-test: 1.0.*
 - tourze/phpunit-symfony-unit-test: 1.*
 
README
English | 中文
[]
(https://packagist.org/packages/tourze/doctrine-uuid-bundle)
[
]
(https://packagist.org/packages/tourze/doctrine-uuid-bundle)
[
]
(https://packagist.org/packages/tourze/doctrine-uuid-bundle)
[
]
(https://travis-ci.org/tourze/doctrine-uuid-bundle)
[
]
(https://scrutinizer-ci.com/g/tourze/doctrine-uuid-bundle)
[
]
(https://packagist.org/packages/tourze/doctrine-uuid-bundle)
[
]
(https://scrutinizer-ci.com/g/tourze/doctrine-uuid-bundle)
A Symfony bundle for automatic UUID (v1/v4) assignment in Doctrine entities using PHP 8 attributes.
Installation
composer require tourze/doctrine-uuid-bundle
Requirements
- PHP 8.1 or higher
 - Symfony 6.4 or higher
 
Features
- Automatic UUID v1 and v4 assignment for entity properties
 - Zero configuration, works out of the box
 - Attribute-driven and easy to use
 - Seamless integration with Doctrine event system
 - Built-in logging for debugging
 - Extensible: custom UUID generation strategies supported
 - Nullable UUID fields supported
 - Automatic database schema updates
 - Compatible with Symfony 6.4+ and Doctrine 2.13+
 
Quick Start
Add the UuidV1Column or UuidV4Column attribute to your entity properties:
use Tourze\DoctrineUuidBundle\Attribute\UuidV1Column; use Tourze\DoctrineUuidBundle\Attribute\UuidV4Column; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class YourEntity { #[ORM\Id] #[ORM\Column(type: 'uuid')] #[UuidV1Column] private string $uuidV1; #[ORM\Column(type: 'uuid')] #[UuidV4Column] private ?string $uuidV4 = null; }
UUIDs will be automatically generated when the entity is persisted.
Configuration
The bundle works with zero configuration. If you need to customize the behavior, you can:
- Create custom UUID attributes by extending the base attributes
 - Override the event listener service to implement custom generation logic
 - Configure logging levels in your Symfony configuration
 
Advanced Usage
You may extend the Attribute or event listener to implement custom UUID generation logic.
Security
- UUID v1 contains MAC address and timestamp information, which may be considered sensitive
 - UUID v4 is cryptographically random and doesn't contain identifiable information
 - Choose the appropriate UUID version based on your security requirements
 - Consider using UUID v4 for public-facing identifiers
 
Common Issues
- UUID not being generated: Ensure your entity uses the correct attributes and the bundle is registered
in 
config/bundles.php. - Database schema issues: Run 
php bin/console doctrine:schema:update --forceto update your database schema. - Performance considerations: UUID v1 is time-based and may be more suitable for database indexing than UUID v4.
 
Documentation
- API Docs
 - Most configuration is automatic. For advanced extension, you may customize the event subscriber.
 
Contributing
- Feel free to submit Issues and PRs
 - Follow PSR code style
 - Please ensure tests pass before submitting PRs
 - Fork the repo, create a branch, push and submit a PR
 
License
- License: MIT
 - Author: Tourze
 
Changelog
See CHANGELOG
Workflow Diagram
See Mermaid.md for a visual workflow.