diff --git a/application/symfony/src/Domain/CRUDManagement/RepositoryFactoryService.php b/application/symfony/src/Domain/CRUDManagement/RepositoryFactoryService.php deleted file mode 100644 index fb4c619..0000000 --- a/application/symfony/src/Domain/CRUDManagement/RepositoryFactoryService.php +++ /dev/null @@ -1,36 +0,0 @@ -entityManager = $entityManager; - } - - /** - * {@inheritdoc} - * - * @see \App\Domain\CRUDManagement\RepositoryFactoryInterface::getRepository() - */ - public function getRepository(EntityInterface $entity): RepositoryInterface - { - $this->entityManager->getRepository(get_class($entity)); - } -} diff --git a/application/symfony/src/Domain/CRUDManagement/RepositoryFactoryServiceInterface.php b/application/symfony/src/Domain/CRUDManagement/RepositoryFactoryServiceInterface.php deleted file mode 100644 index f92b6a7..0000000 --- a/application/symfony/src/Domain/CRUDManagement/RepositoryFactoryServiceInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - 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); + } +} diff --git a/application/symfony/src/Domain/RepositoryManagement/LayerRepositoryFactoryServiceInterface.php b/application/symfony/src/Domain/RepositoryManagement/LayerRepositoryFactoryServiceInterface.php new file mode 100644 index 0000000..3b2d04c --- /dev/null +++ b/application/symfony/src/Domain/RepositoryManagement/LayerRepositoryFactoryServiceInterface.php @@ -0,0 +1,20 @@ +version = 0; diff --git a/application/symfony/src/Entity/EntityInterface.php b/application/symfony/src/Entity/EntityInterface.php index 65df144..975ed52 100644 --- a/application/symfony/src/Entity/EntityInterface.php +++ b/application/symfony/src/Entity/EntityInterface.php @@ -9,6 +9,6 @@ use App\Entity\Attribut\SlugAttributInterface; /** * @author kevinfrantz */ -interface EntityInterface extends VersionAttributInterface, IdAttributInterface,SlugAttributInterface +interface EntityInterface extends VersionAttributInterface, IdAttributInterface, SlugAttributInterface { } diff --git a/application/symfony/src/Entity/Source/AbstractSource.php b/application/symfony/src/Entity/Source/AbstractSource.php index 7daebde..136f0c5 100644 --- a/application/symfony/src/Entity/Source/AbstractSource.php +++ b/application/symfony/src/Entity/Source/AbstractSource.php @@ -9,7 +9,6 @@ use App\Entity\Attribut\LawAttribut; use App\Entity\Meta\LawInterface; use App\Entity\Meta\Law; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; -use Symfony\Component\Validator\Constraints as Assert; use App\Entity\Attribut\CreatorRelationAttribut; use App\Entity\Meta\Relation\Parent\CreatorRelationInterface; use App\Entity\Meta\Relation\Parent\CreatorRelation; diff --git a/application/symfony/tests/Unit/Domain/RepositoryManagement/LayerRepositoryFactoryServiceTest.php b/application/symfony/tests/Unit/Domain/RepositoryManagement/LayerRepositoryFactoryServiceTest.php new file mode 100644 index 0000000..1b29dfa --- /dev/null +++ b/application/symfony/tests/Unit/Domain/RepositoryManagement/LayerRepositoryFactoryServiceTest.php @@ -0,0 +1,34 @@ +get('doctrine')->getManager(); + $this->layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager); + } + + public function testGetRepository(): void + { + foreach (LayerRepositoryFactoryService::LAYER_CLASS_MAP as $layer => $class) { + $repositoy = $this->layerRepositoryFactoryService->getRepository($layer); + $this->assertInstanceOf(RepositoryInterface::class, $repositoy); + } + } +}