setono/doctrine-object-manager-trait

This package is abandoned and no longer maintained. The author suggests using the setono/doctrine-orm-trait package instead.

A very simple library that offers an object manager trait to get the object manager for a given class

Maintainers

πŸ‘ loevgaard

Package info

github.com/Setono/doctrine-object-manager-trait

pkg:composer/setono/doctrine-object-manager-trait

Statistics

Installs: 166 318

Dependents: 13

Suggesters: 0

Stars: 0

Open Issues: 0

v1.3.0 2024-04-16 08:25 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT b965196da3409745fbfbcdca6e2676c2029ef732

  • Joachim LΓΈvgaard <joachim.woop@loevgaard.dk>

README

πŸ‘ Latest Version
πŸ‘ Software License
πŸ‘ Build Status
πŸ‘ Code Coverage
πŸ‘ Mutation testing

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-object-manager-trait

Usage

<?php
use Doctrine\Persistence\ManagerRegistry;
use Setono\DoctrineObjectManagerTrait\ORM\ORMManagerTrait;

final class YourClass
{
 use ORMManagerTrait;
 
 public function __construct(ManagerRegistry $managerRegistry)
 {
 $this->managerRegistry = $managerRegistry;
 }
 
 public function someMethod(): void
 {
 /**
 * $entity is an entity managed by Doctrine or a class-string representing an entity managed by Doctrine
 */
 $entity = ;
 
 /**
 * Because we used the ORMManagerTrait above the getManager method will return an EntityManagerInterface
 * 
 * @var \Doctrine\ORM\EntityManagerInterface $manager 
 */
 $manager = $this->getManager($entity);
 
 $manager->persist($entity);
 $manager->flush();
 }
}