Initial commit
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Common;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* Factory for doctrine repositories - provides adapter for the service locator pattern used
|
||||
* to access repositories via entity manager, for the ability to use repositories in DI container
|
||||
*
|
||||
* @author Jan Pavlíček <jan.pavlicek@altekpro.cz>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class EntityRepositoryFactory
|
||||
{
|
||||
/**
|
||||
* @var Doctrine\ORM\EntityManager
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates the repository using entity manager
|
||||
*/
|
||||
public function create(string $class) : EntityRepository
|
||||
{
|
||||
return $this->em->getRepository($class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user