From 51667ee3819d96eccb3bdbb49d2bfba372a17abd Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Mon, 7 Jan 2019 22:33:51 +0100 Subject: [PATCH] Optimized SecureCRUDManagement Draft --- .../CRUD/Create/AbstractSecureCreator.php | 2 +- .../CRUD/Create/SecureCreatorInterface.php | 2 +- .../CRUD/Create/SecureHeredityCreator.php | 21 +++++++++ .../CRUD/Create/SecureMemberCreator.php | 6 --- .../CRUD/Create/SecureRightCreator.php | 21 +++++++++ .../AbstractSecureCRUDFactoryService.php | 2 +- .../Factory/SecureCreatorFactoryService.php | 24 +++++++--- .../SecureCreatorFactoryServiceTest.php | 45 +++++++++++++++++++ 8 files changed, 107 insertions(+), 16 deletions(-) create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreator.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureRightCreator.php create mode 100644 application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceTest.php diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php index d175d92..01a4bbf 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php @@ -2,7 +2,7 @@ namespace App\Domain\SecureCRUDManagement\CRUD\Create; -use App\Domain\SecureCRUDManagement\AbstractSecureCRUD; +use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUD; /** * @author kevinfrantz diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreatorInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreatorInterface.php index 14eb7ad..231e98b 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreatorInterface.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureCreatorInterface.php @@ -2,8 +2,8 @@ namespace App\Domain\SecureCRUDManagement\CRUD\Create; -use App\Domain\SecureCRUDManagement\SecureCRUDInterface; use App\Entity\EntityInterface; +use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface; /** * @todo Implement! diff --git a/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreator.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreator.php new file mode 100644 index 0000000..06d4d29 --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureHeredityCreator.php @@ -0,0 +1,21 @@ +getCrud($crud); } diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php index 8a34609..8be756a 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php @@ -3,9 +3,8 @@ namespace App\Domain\SecureCRUDManagement\Factory; use App\Entity\Meta\RightInterface; -use App\DBAL\Types\Meta\Right\LayerType; use App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface; -use App\Domain\SecureCRUDManagement\CRUD\Create\SecureSourceCreator; +use App\DBAL\Types\Meta\Right\CRUDType; /** * @author kevinfrantz @@ -14,6 +13,19 @@ use App\Domain\SecureCRUDManagement\CRUD\Create\SecureSourceCreator; */ final class SecureCreatorFactoryService extends AbstractSecureCRUDFactoryService { + const CRUD_TYPE = CRUDType::CREATE; + + /** + * @param string $layer + * @param string $crud + * + * @return string + */ + protected function getClassName(string $layer, string $crud): string + { + return 'Secure'.ucfirst(strtolower($layer)).'Creator'; + } + /** * {@inheritdoc} * @@ -21,10 +33,8 @@ final class SecureCreatorFactoryService extends AbstractSecureCRUDFactoryService */ public function create(RightInterface $requestedRight): SecureCreatorInterface { - switch ($requestedRight->getLayer()) { - case LayerType::SOURCE: - return new SecureSourceCreator($this->request, $this->security); - case LayerType::MEMBER: - } + $namespace = $this->getCRUDNamespace($requestedRight->getLayer(), self::CRUD_TYPE); + + return new $namespace($this->request, $this->security); } } diff --git a/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceTest.php b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceTest.php new file mode 100644 index 0000000..1813f18 --- /dev/null +++ b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceTest.php @@ -0,0 +1,45 @@ +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); + } + } + } +}