tourze / doctrine-helper
Doctrine Helper
Installs: 2 795
Dependents: 12
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- doctrine/common: ^3.5
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-04-27 09:47:05 UTC
README
A lightweight helper library to simplify and optimize your usage of Doctrine ORM in PHP projects.
Features
- CacheHelper: Generate cache IDs and tags for Doctrine entities and objects.
- EntityDetector: Determine whether a class is a Doctrine entity.
- ReflectionHelper: Simplify reflection operations for Doctrine entities, properties, and custom attributes, with caching for performance.
Installation
- Requires PHP >= 8.1
- Requires doctrine/orm >= 2.20 or >= 3.0
- Requires doctrine/common >= 3.5
Install via Composer:
composer require tourze/doctrine-helper
Quick Start
CacheHelper Example
use Tourze\DoctrineHelper\CacheHelper; // Get cache ID for a class $cacheId = CacheHelper::getClassId(User::class); // Get cache tags for a class $tags = CacheHelper::getClassTags(User::class); // Get cache tags for a class with ID $tagsWithId = CacheHelper::getClassTags(User::class, 1); // Get cache tags for an object $objectTags = CacheHelper::getObjectTags($user);
EntityDetector Example
use Tourze\DoctrineHelper\EntityDetector; // Check if a class is a Doctrine entity if (EntityDetector::isEntityClass(User::class)) { // This is a Doctrine entity }
ReflectionHelper Example
use Tourze\DoctrineHelper\ReflectionHelper; // Get class reflection $reflection = ReflectionHelper::getClassReflection(User::class); // Get property reflection $property = ReflectionHelper::getReflectionProperty($user, 'email'); // Get all properties $properties = ReflectionHelper::getProperties(User::class); // Get all methods $methods = ReflectionHelper::getMethods(User::class); // Get property attributes $attributes = ReflectionHelper::getPropertyAttributes($reflection, SomeAttribute::class);
Documentation
- See source code and unit tests for detailed API usage.
- Attribute and annotation reading supported.
- Reflection caching optimizes performance.
Contributing
- Issues and pull requests are welcome.
- Follow PSR-12 coding style.
- Ensure all PHPUnit tests pass before submitting.
License
MIT License. See LICENSE for details.
Changelog
See Git commit history for changes and releases.