Download the PHP package tourze/doctrine-random-bundle without Composer
On this page you can find all versions of the php package tourze/doctrine-random-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package doctrine-random-bundle
Doctrine Random Bundle
中文
A Symfony bundle that provides automatic random string generation for Doctrine entity properties and random database query functionality with PHP attributes.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Configuration
- RandomService Usage
- Advanced Usage
- Advanced Details
- Security
- Contribution Guide
- License
- Changelog
- Author
Features
- Random String Generation: Generate random string values for entity properties using PHP attributes
- Random Database Queries: Service to fetch random records from database with caching and locking support
- Configurable: Customizable prefix and string length for random strings
- Automatic Generation: Triggers on entity creation (Doctrine prePersist event)
- Non-Destructive: Skips generation if property already has a value
- Performance Optimized: Uses caching and distributed locking to prevent conflicts
- Symfony Integration: Simple integration with Symfony auto-configuration
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine Bundle 2.13 or higher
- Doctrine ORM 2.20/3.0 or higher
Installation
This bundle is auto-registered by Symfony Flex. No extra configuration is required.
Quick Start
Add the RandomStringColumn attribute to your entity property:
When you persist a new entity, the randomId property will be automatically filled if it is empty:
Configuration
The RandomStringColumn attribute accepts the following parameters:
prefix: String prefix for the random value (default: '')length: Length of the random string (default: 16)
RandomService Usage
The bundle also provides a RandomService for fetching random records from the
database with caching and locking support:
RandomService Features
- Distributed Locking: Prevents multiple processes from getting the same random record
- Caching: Caches ID lists for better performance (1-minute TTL)
- Flexible Querying: Works with any QueryBuilder with WHERE conditions
- Configurable Range: Limits the cached ID range to optimize memory usage
Advanced Usage
Custom Random String Generation
You can use multiple RandomStringColumn attributes on different properties:
Advanced RandomService Usage
The RandomService supports complex queries and offers fine-grained control:
Advanced Details
- The bundle uses a Doctrine event listener (
RandomStringListener) to automatically generate random strings for properties marked with theRandomStringColumnattribute during theprePersistevent. - If the property already has a value, it will not be overwritten.
- The random string is composed of numbers and upper/lowercase letters.
- The
RandomServiceuses Symfony's Lock component and Cache component for performance optimization.
Security
- Random strings are generated using PHP's
random_int()function for cryptographic security - The bundle respects existing property values and never overwrites them
- Distributed locking prevents race conditions in concurrent environments
Contribution Guide
Contributions are welcome! To contribute:
- Open an issue for bug reports or feature requests.
- Submit a pull request with clear description and relevant tests.
- Follow PSR coding standards.
- Run tests with PHPUnit before submitting.
License
This bundle is released under the MIT License. See the LICENSE file for details.
Changelog
- v0.1.0: Initial release with random string attribute and random query service support.
Author
Maintained by tourze.
All versions of doctrine-random-bundle with dependencies
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/cache-contracts Version ^3
symfony/config Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/doctrine-bridge Version ^7.3
symfony/framework-bundle Version ^7.3
symfony/http-kernel Version ^7.3
symfony/lock Version ^7.3
symfony/property-access 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.*