mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 01:09:41 +00:00 
			
		
		
		
	Optimized LayerRepositoryFactoryService
This commit is contained in:
		| @@ -1,36 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\CRUDManagement; | ||||
|  | ||||
| use App\Entity\EntityInterface; | ||||
| use App\Repository\RepositoryInterface; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| final class RepositoryFactoryService implements RepositoryFactoryServiceInterface | ||||
| { | ||||
|     /** | ||||
|      * @var EntityManagerInterface | ||||
|      */ | ||||
|     private $entityManager; | ||||
|  | ||||
|     /** | ||||
|      * @param EntityManagerInterface $entityManager | ||||
|      */ | ||||
|     private function __construct(EntityManagerInterface $entityManager) | ||||
|     { | ||||
|         $this->entityManager = $entityManager; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Domain\CRUDManagement\RepositoryFactoryInterface::getRepository() | ||||
|      */ | ||||
|     public function getRepository(EntityInterface $entity): RepositoryInterface | ||||
|     { | ||||
|         $this->entityManager->getRepository(get_class($entity)); | ||||
|     } | ||||
| } | ||||
| @@ -1,21 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\CRUDManagement; | ||||
|  | ||||
| use App\Repository\RepositoryInterface; | ||||
| use App\Entity\EntityInterface; | ||||
|  | ||||
| /** | ||||
|  * Offers a fabric for entity repositories. | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RepositoryFactoryServiceInterface | ||||
| { | ||||
|     /** | ||||
|      * @param EntityInterface $entity | ||||
|      * | ||||
|      * @return RepositoryInterface The repositoy of the interface | ||||
|      */ | ||||
|     public function getRepository(EntityInterface $entity): RepositoryInterface; | ||||
| } | ||||
| @@ -9,9 +9,9 @@ A folder MUST end on the suffix ** *Management ** to show that it has the purpos | ||||
|  | ||||
| # Domain Overview | ||||
|  | ||||
| ## CRUD Management | ||||
| ### Repository Factory Service | ||||
| Offers a fabric for entity repositories. | ||||
| ## Repository Management | ||||
| ### Layer Repository Factory Service | ||||
| Offers a fabric to produce entity repositories by layer | ||||
| ## Entity Management | ||||
| ### Entity Meta Information ### | ||||
| Offers some meta information about an entity | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
| @@ -10,6 +10,7 @@ use App\Domain\RequestManagement\Right\RequestedRightInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  * | ||||
|  * @todo Implement! | ||||
|  */ | ||||
| class RequestedAction extends RequestedUser implements RequestedActionInterface | ||||
|   | ||||
| @@ -9,6 +9,7 @@ use App\Domain\RequestManagement\User\RequestedUserInterface; | ||||
|  * An action containes multiple attributes which are neccessary to process a request. | ||||
|  * | ||||
|  * @see ActionType | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RequestedActionInterface extends ActionTypeAttributInterface, RequestedUserInterface | ||||
|   | ||||
| @@ -4,7 +4,9 @@ namespace App\Domain\RequestManagement\Action; | ||||
|  | ||||
| /** | ||||
|  * Allows to use a action as a service. | ||||
|  * | ||||
|  * @todo Implement! | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RequestedActionServiceInterface | ||||
|   | ||||
| @@ -45,7 +45,7 @@ abstract class AbstractEntity implements EntityInterface | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $slug; | ||||
|      | ||||
|  | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->version = 0; | ||||
|   | ||||
| @@ -9,6 +9,6 @@ use App\Entity\Attribut\SlugAttributInterface; | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface EntityInterface extends VersionAttributInterface, IdAttributInterface,SlugAttributInterface | ||||
| interface EntityInterface extends VersionAttributInterface, IdAttributInterface, SlugAttributInterface | ||||
| { | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -0,0 +1,34 @@ | ||||
| <?php | ||||
|  | ||||
| namespace tests\Unit\Domain\RepositoryManagement; | ||||
|  | ||||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||||
| use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; | ||||
| use App\Domain\RepositoryManagement\LayerRepositoryFactoryService; | ||||
| use App\Repository\RepositoryInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class LayerRepositoryFactoryServiceTest extends KernelTestCase | ||||
| { | ||||
|     /** | ||||
|      * @var LayerRepositoryFactoryServiceInterface | ||||
|      */ | ||||
|     private $layerRepositoryFactoryService; | ||||
|  | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         self::bootKernel(); | ||||
|         $entityManager = self::$container->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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user