Skip to content

Instantly share code, notes, and snippets.

@raitocz
Created August 9, 2019 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raitocz/faec272acd3868c7a3d342645e0e408d to your computer and use it in GitHub Desktop.
Save raitocz/faec272acd3868c7a3d342645e0e408d to your computer and use it in GitHub Desktop.
Traits to get multiple entity managers
<?php declare(strict_types=1);
namespace EryseClient\Utility;
use App\Utility\EntityManager\LocalEntityManagerTrait;
use App\Utility\EntityManager\RemoteEntityManagerTrait;
trait EntityManagersTrait
{
use LocalEntityManagerTrait;
use RemoteEntityManagerTrait;
}
<?php declare(strict_types=1);
namespace App\Utility\EntityManager;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
trait LocalEntityManagerTrait
{
/** @var EntityManagerInterface $em */
protected $emLocal;
/**
* @required
* @param ManagerRegistry $managerRegistry
*/
public function setLocalEntityManager(ManagerRegistry $managerRegistry)
{
$this->emLocal = $managerRegistry->getManager('app-local');
}
}
<?php declare(strict_types=1);
namespace App\Utility\EntityManager;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
trait RemoteEntityManagerTrait
{
/** @var EntityManagerInterface $em */
protected $emRemote;
/**
* @required
* @param ManagerRegistry $managerRegistry
*/
public function setRemoteEntityManager(ManagerRegistry $managerRegistry)
{
$this->emRemote = $managerRegistry->getManager('app-remote');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment