diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreate.php similarity index 62% rename from application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreate.php index 01a4bbf..72ac7be 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreate.php @@ -7,6 +7,6 @@ use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUD; /** * @author kevinfrantz */ -abstract class AbstractSecureCreator extends AbstractSecureCRUD implements SecureCreatorInterface +abstract class AbstractSecureCreate extends AbstractSecureCRUD implements SecureCreateInterface { } diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreatorInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreateInterface.php similarity index 84% rename from application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreatorInterface.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreateInterface.php index 231e98b..a2ce47f 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreatorInterface.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreateInterface.php @@ -10,7 +10,7 @@ use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface; * * @author kevinfrantz */ -interface SecureCreatorInterface extends SecureCRUDInterface +interface SecureCreateInterface extends SecureCRUDInterface { /** * @return EntityInterface The created entity diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreator.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreate.php similarity index 57% rename from application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreator.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreate.php index 06d4d29..6c317ec 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreator.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreate.php @@ -7,13 +7,12 @@ use App\Entity\EntityInterface; /** * @author kevinfrantz */ -final class SecureHeredityCreator extends AbstractSecureCreator +final class SecureHeredityCreate extends AbstractSecureCreate { /** * @todo Implement - * {@inheritdoc} * - * @see \App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface::create() + * @return EntityInterface */ public function create(): EntityInterface { diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureMemberCreator.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureMemberCreate.php similarity index 77% rename from application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureMemberCreator.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureMemberCreate.php index e295c99..8350f2f 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureMemberCreator.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureMemberCreate.php @@ -7,7 +7,7 @@ use App\Entity\EntityInterface; /** * @author kevinfrantz */ -final class SecureMemberCreator extends AbstractSecureCreator +final class SecureMemberCreate extends AbstractSecureCreate { public function create(): EntityInterface { diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureRightCreator.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureRightCreate.php similarity index 57% rename from application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureRightCreator.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureRightCreate.php index a94f61c..d2659a8 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureRightCreator.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureRightCreate.php @@ -7,13 +7,12 @@ use App\Entity\EntityInterface; /** * @author kevinfrantz */ -final class SecureRightCreator extends AbstractSecureCreator +final class SecureRightCreate extends AbstractSecureCreate { /** * @todo Implement! - * {@inheritdoc} * - * @see \App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface::create() + * @return EntityInterface */ public function create(): EntityInterface { diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureSourceCreator.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureSourceCreate.php similarity index 88% rename from application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureSourceCreator.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureSourceCreate.php index c3f9381..369e1ea 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureSourceCreator.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureSourceCreate.php @@ -10,7 +10,7 @@ use App\Entity\Source\Primitive\Text\TextSource; * * @todo Implement! */ -final class SecureSourceCreator extends AbstractSecureCreator +final class SecureSourceCreate extends AbstractSecureCreate { /** * {@inheritdoc} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryService.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryService.php similarity index 50% rename from application/symfony/src/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryService.php rename to application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryService.php index 3ed5e35..f5a237a 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryService.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryService.php @@ -2,27 +2,34 @@ namespace App\Domain\SecureCRUDManagement\Factory; +use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface; +use App\Entity\Meta\RightInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Security; use Symfony\Component\HttpFoundation\RequestStack; +use Doctrine\ORM\EntityManagerInterface; /** * @author kevinfrantz * - * @todo Implement! - * @todo substitute through child classes! + * @todo Improve code performance */ -abstract class AbstractSecureCRUDFactoryService implements SecureCRUDFactoryServiceInterface +final class SecureCRUDFactoryService implements SecureCRUDFactoryServiceInterface { /** * @var Request */ - protected $request; + private $request; /** * @var Security */ - protected $security; + private $security; + + /** + * @var EntityManagerInterface + */ + private $entityManager; /** * @param string $crud @@ -40,7 +47,7 @@ abstract class AbstractSecureCRUDFactoryService implements SecureCRUDFactoryServ * * @return string */ - protected function getClassName(string $layer, string $crud): string + private function getClassName(string $layer, string $crud): string { return 'Secure'.ucfirst(strtolower($layer)).$this->getCrud($crud); } @@ -50,14 +57,27 @@ abstract class AbstractSecureCRUDFactoryService implements SecureCRUDFactoryServ * * @return string */ - protected function getCRUDNamespace(string $layer, string $crud): string + private function getCRUDNamespace(string $layer, string $crud): string { return 'App\\Domain\\SecureCRUDManagement\\CRUD\\'.$this->getCrud($crud).'\\'.$this->getClassName($layer, $crud); } - public function __construct(RequestStack $requestStack, Security $security) + public function __construct(RequestStack $requestStack, Security $security, EntityManagerInterface $entityManager) { $this->request = $requestStack->getCurrentRequest(); $this->security = $security; + $this->entityManager = $entityManager; + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface::create() + */ + public function create(RightInterface $requestedRight): SecureCRUDInterface + { + $namespace = $this->getCRUDNamespace($requestedRight->getLayer(), $requestedRight->getType()); + + return new $namespace($this->request, $this->security, $this->entityManager); } } diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php index 7b216d1..9661e64 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php @@ -3,7 +3,7 @@ namespace App\Domain\SecureCRUDManagement\Factory; use App\Entity\Meta\RightInterface; -use App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface; +use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface; /** * @author kevinfrantz @@ -11,7 +11,7 @@ use App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface; interface SecureCRUDFactoryServiceInterface { /** - * @return SecureCreatorInterface + * @return SecureCRUDInterface */ - public function create(RightInterface $requestedRight): SecureCreatorInterface; + public function create(RightInterface $requestedRight): SecureCRUDInterface; } diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php deleted file mode 100644 index 8be756a..0000000 --- a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php +++ /dev/null @@ -1,40 +0,0 @@ -getCRUDNamespace($requestedRight->getLayer(), self::CRUD_TYPE); - - return new $namespace($this->request, $this->security); - } -} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceInterface.php deleted file mode 100644 index 484835c..0000000 --- a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -getCRUDNamespace($layer, $crud); - } - - public function create(RightInterface $requestedRight): SecureCreatorInterface - { - } - }; - $result = $abstractSecureCRUDFactoryService->publicGetCRUDNamespace('Layer', 'Crud'); - $this->assertEquals('App\\Domain\\SecureCRUDManagement\\CRUD\\Crud\\SecureLayerCrud', $result); - } -} diff --git a/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceTest.php b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceTest.php new file mode 100644 index 0000000..44b3bb0 --- /dev/null +++ b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceTest.php @@ -0,0 +1,58 @@ + [ + LayerType::LAW, + ], + CRUDType::DELETE => [ + LayerType::LAW, + ], + CRUDType::READ => [], + CRUDType::UPDATE => [], + ]; + + /** + * @var SecureCRUDFactoryServiceInterface + */ + private $secureCRUDFactoryService; + + public function setUp(): void + { + self::bootKernel(); + $requestStack = self::$container->get('request_stack'); + $security = new Security(self::$kernel->getContainer()); + $entityManager = self::$container->get('doctrine.orm.default_entity_manager'); + $this->secureCRUDFactoryService = new SecureCRUDFactoryService($requestStack, $security, $entityManager); + } + + public function testCreate(): void + { + foreach (CRUDType::getChoices() as $crud) { + foreach (LayerType::getChoices() as $layer) { + if (!in_array($layer, self::EXCLUDED_TYPES[$crud])) { + $requestedRight = new Right(); + $requestedRight->setLayer($layer); + $requestedRight->setType($crud); + $secureCreator = $this->secureCRUDFactoryService->create($requestedRight); + $this->assertInstanceOf(SecureCRUDInterface::class, $secureCreator); + } + } + } + } +} diff --git a/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceTest.php b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceTest.php deleted file mode 100644 index 1813f18..0000000 --- a/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceTest.php +++ /dev/null @@ -1,45 +0,0 @@ -get('request_stack'); - $security = new Security(self::$kernel->getContainer()); - $this->secureCreatorFactoryService = new SecureCreatorFactoryService($requestStack, $security); - } - - public function testCreate(): void - { - $excludedTypes = [ - LayerType::LAW, - ]; - foreach (LayerType::getChoices() as $layer) { - if (!in_array($layer, $excludedTypes)) { - $requestedRight = new Right(); - $requestedRight->setLayer($layer); - $secureCreator = $this->secureCreatorFactoryService->create($requestedRight); - $this->assertInstanceOf(SecureCreatorInterface::class, $secureCreator); - } - } - } -}