mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized LayerRepositoryFactoryService
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RepositoryManagement;
|
||||
|
||||
use App\Repository\RepositoryInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\DBAL\Types\Meta\Right\LayerType;
|
||||
use App\Exception\NotSetException;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class LayerRepositoryFactoryService implements LayerRepositoryFactoryServiceInterface
|
||||
{
|
||||
const LAYER_CLASS_MAP = [
|
||||
LayerType::SOURCE => AbstractSource::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @param string $layer
|
||||
*
|
||||
* @throws NotSetException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRepositoryClassName(string $layer): string
|
||||
{
|
||||
$map = self::LAYER_CLASS_MAP;
|
||||
if (array_key_exists($layer, $map)) {
|
||||
return $map[$layer];
|
||||
}
|
||||
throw new NotSetException('The requested layer is not mapped!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $layer
|
||||
*
|
||||
* @return RepositoryInterface
|
||||
*/
|
||||
public function getRepository(string $layer): RepositoryInterface
|
||||
{
|
||||
$repositoryClassName = $this->getRepositoryClassName($layer);
|
||||
|
||||
return $this->entityManager->getRepository($repositoryClassName);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RepositoryManagement;
|
||||
|
||||
use App\Repository\RepositoryInterface;
|
||||
|
||||
/**
|
||||
* Offers a fabric to produce entity repositories by layer.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface LayerRepositoryFactoryServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param string $layer
|
||||
*
|
||||
* @return RepositoryInterface
|
||||
*/
|
||||
public function getRepository(string $layer): RepositoryInterface;
|
||||
}
|
Reference in New Issue
Block a user