setono / doctrine-orm-trait
A very simple library that offers a trait to get the object manager and repository for a given class
Fund package maintenance!
Setono
Installs: 27 141
Dependents: 13
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- doctrine/orm: ^2.8 || ^3.1
- doctrine/persistence: ^1.3 || ^2.5 || ^3.1
Requires (Dev)
- infection/infection: ^0.27
- phpspec/prophecy-phpunit: ^2.2
- phpunit/phpunit: ^10.5
- psalm/plugin-phpunit: ^0.19
- setono/code-quality-pack: ^2.7
This package is auto-updated.
Last update: 2024-12-07 10:14:40 UTC
README
If you are like and me and usually don't inject entity managers directly, but inject the manager registry instead then this little library will come in handy.
Installation
composer require setono/doctrine-orm-trait
Usage
<?php use Doctrine\Persistence\ManagerRegistry; use Setono\Doctrine\ORMTrait; final class YourClass { /** * Include this trait to use the getManager() and getRepository() methods below */ use ORMTrait; public function __construct(ManagerRegistry $managerRegistry) { $this->managerRegistry = $managerRegistry; } public function someMethod(): void { /** * $entity<T> is an entity managed by Doctrine or a class-string representing an entity managed by Doctrine */ $entity = ; /** @var \Doctrine\ORM\EntityRepository<T> $repository */ $repository = $this->getRepository($entity); /** * @var \Doctrine\ORM\EntityManagerInterface $manager */ $manager = $this->getManager($entity); $manager->persist($entity); $manager->flush(); } }