<?php
namespace Boab\CmsBundle\ORM;
use Boab\CmsBundle\Service\PaginationInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManagerInterface;
class RepositoryFactory
{
private $entityManager;
private $pagination;
public function __construct(EntityManagerInterface $entityManager, PaginationInterface $pagination)
{
$this->entityManager = $entityManager;
$this->pagination = $pagination;
}
public function getRepository(string $entityName): EntityRepository
{
$metadata = $this->entityManager->getClassMetadata($entityName);
$repositoryClassName = $metadata->customRepositoryClassName ?: $this->entityManager->getConfiguration()->getDefaultRepositoryClassName();
$repository = new $repositoryClassName($this->entityManager, $metadata);
$repository->setPagination($this->pagination);
return $repository;
}
}