From 6b29c5a57759b13d1051e3816e6278f089f737a9 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Mon, 7 Jan 2019 21:19:20 +0100 Subject: [PATCH] Optimized SecureCRUDManagement Draft --- .../Controller/API/AbstractAPIController.php | 3 +- .../API/Meta/HeredityApiController.php | 7 +- .../Controller/API/Meta/LawApiController.php | 7 +- .../API/Meta/MemberApiController.php | 7 +- .../API/Meta/RightApiController.php | 7 +- .../API/Source/SourceApiController.php | 82 +++++++++---------- .../{ => CRUD}/AbstractSecureCRUD.php | 4 +- .../CRUD/Create/AbstractSecureCreator.php | 12 +++ .../Create/SecureCreatorInterface.php | 2 +- .../CRUD/Create/SecureMemberCreator.php | 22 +++++ .../CRUD/Create/SecureSourceCreator.php | 27 ++++++ .../{ => CRUD}/SecureCRUDInterface.php | 2 +- .../Create/AbstractSecureCreator.php | 12 --- .../Create/SecureSourceCreator.php | 28 ------- .../Create/SecureSourceCreatorInterface.php | 12 --- .../AbstractSecureCRUDFactoryService.php | 63 ++++++++++++++ .../SecureCRUDFactoryServiceInterface.php | 17 ++++ .../Factory/SecureCreatorFactoryService.php | 30 +++++++ .../SecureCreatorFactoryServiceInterface.php | 10 +++ .../SecureCRUDFactoryService.php | 42 ---------- .../AbstractSecureCRUDFactoryServiceTest.php | 34 ++++++++ 21 files changed, 271 insertions(+), 159 deletions(-) rename application/symfony/src/Domain/SecureCRUDManagement/{ => CRUD}/AbstractSecureCRUD.php (62%) create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/AbstractSecureCreator.php rename application/symfony/src/Domain/SecureCRUDManagement/{ => CRUD}/Create/SecureCreatorInterface.php (85%) create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureMemberCreator.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/CRUD/Create/SecureSourceCreator.php rename application/symfony/src/Domain/SecureCRUDManagement/{ => CRUD}/SecureCRUDInterface.php (66%) delete mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Create/AbstractSecureCreator.php delete mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreator.php delete mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryService.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryService.php create mode 100644 application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceInterface.php delete mode 100644 application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDFactoryService.php create mode 100644 application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryServiceTest.php diff --git a/application/symfony/src/Controller/API/AbstractAPIController.php b/application/symfony/src/Controller/API/AbstractAPIController.php index c13e96d..ce1d5c4 100644 --- a/application/symfony/src/Controller/API/AbstractAPIController.php +++ b/application/symfony/src/Controller/API/AbstractAPIController.php @@ -5,7 +5,6 @@ namespace App\Controller\API; use App\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; -use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService; /** * @author kevinfrantz @@ -21,7 +20,7 @@ abstract class AbstractAPIController extends AbstractController * * @return Response */ - abstract public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response; +// abstract public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response; /** * @param Request $request HTTP Method GET diff --git a/application/symfony/src/Controller/API/Meta/HeredityApiController.php b/application/symfony/src/Controller/API/Meta/HeredityApiController.php index 99f1988..dc85937 100644 --- a/application/symfony/src/Controller/API/Meta/HeredityApiController.php +++ b/application/symfony/src/Controller/API/Meta/HeredityApiController.php @@ -5,7 +5,6 @@ namespace App\Controller\API\Meta; use App\Controller\API\AbstractAPIController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService; /** * @author kevinfrantz @@ -18,9 +17,9 @@ class HeredityApiController extends AbstractAPIController { } - public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response - { - } +// public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response +// { +// } public function update(Request $request, $identifier): Response { diff --git a/application/symfony/src/Controller/API/Meta/LawApiController.php b/application/symfony/src/Controller/API/Meta/LawApiController.php index d7522f0..ad6b37c 100644 --- a/application/symfony/src/Controller/API/Meta/LawApiController.php +++ b/application/symfony/src/Controller/API/Meta/LawApiController.php @@ -5,7 +5,6 @@ namespace App\Controller\API\Meta; use App\Controller\API\AbstractAPIController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService; /** * @author kevinfrantz @@ -18,9 +17,9 @@ class LawApiController extends AbstractAPIController { } - public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response - { - } +// public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response +// { +// } public function update(Request $request, $identifier): Response { diff --git a/application/symfony/src/Controller/API/Meta/MemberApiController.php b/application/symfony/src/Controller/API/Meta/MemberApiController.php index 99cfd56..5ba6533 100644 --- a/application/symfony/src/Controller/API/Meta/MemberApiController.php +++ b/application/symfony/src/Controller/API/Meta/MemberApiController.php @@ -5,7 +5,6 @@ namespace App\Controller\API\Meta; use App\Controller\API\AbstractAPIController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService; /** * @author kevinfrantz @@ -18,9 +17,9 @@ class MemberApiController extends AbstractAPIController { } - public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response - { - } +// public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response +// { +// } public function update(Request $request, $identifier): Response { diff --git a/application/symfony/src/Controller/API/Meta/RightApiController.php b/application/symfony/src/Controller/API/Meta/RightApiController.php index 218724b..c255ba6 100644 --- a/application/symfony/src/Controller/API/Meta/RightApiController.php +++ b/application/symfony/src/Controller/API/Meta/RightApiController.php @@ -5,7 +5,6 @@ namespace App\Controller\API\Meta; use App\Controller\API\AbstractAPIController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService; /** * @author kevinfrantz @@ -18,9 +17,9 @@ class RightApiController extends AbstractAPIController { } - public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response - { - } +// public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response +// { +// } public function update(Request $request, $identifier): Response { diff --git a/application/symfony/src/Controller/API/Source/SourceApiController.php b/application/symfony/src/Controller/API/Source/SourceApiController.php index 5209568..a48c022 100644 --- a/application/symfony/src/Controller/API/Source/SourceApiController.php +++ b/application/symfony/src/Controller/API/Source/SourceApiController.php @@ -7,8 +7,6 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Request; use App\Controller\API\AbstractAPIController; use App\Entity\Source\PureSource; -use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService; -use App\Domain\SecureCRUDManagement\Create\SecureSourceCreatorInterface; /** * @author kevinfrantz @@ -30,51 +28,51 @@ class SourceApiController extends AbstractAPIController { } - /** - * @Route("/{_locale}/api/source.{_format}", - * defaults={"_format"="json"} , - * methods={"POST","GET"} - * ) - * {@inheritdoc} - * - * @see \App\Controller\API\AbstractAPIController::create() - */ - public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response - { - $response = new Response(); - if (!$this->getUser()) { - //throw $this->createAccessDeniedException('The user must be logged in!'); - } - - if (Request::METHOD_POST === $request->getMethod()) { - $response = new Response(); - $response->setContent('Post Request!'); - - return $response; - } - /** - * @var SecureSourceCreatorInterface - */ - $sourceCreator = $crudFactory->create(); - $response->setContent($sourceCreator->create()->getText()); - - return $response; - +// /** +// * @Route("/{_locale}/api/source.{_format}", +// * defaults={"_format"="json"} , +// * methods={"POST","GET"} +// * ) +// * {@inheritdoc} +// * +// * @see \App\Controller\API\AbstractAPIController::create() +// */ +// public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response +// { // $response = new Response(); -// $response->setContent('GET Request!'); +// if (!$this->getUser()) { +// //throw $this->createAccessDeniedException('The user must be logged in!'); +// } + +// if (Request::METHOD_POST === $request->getMethod()) { +// $response = new Response(); +// $response->setContent('Post Request!'); + +// return $response; +// } +// /** +// * @var SecureSourceCreatorInterface +// */ +// $sourceCreator = $crudFactory->create(); +// $response->setContent($sourceCreator->create()->getText()); // return $response; -// $requestedSource = new PureSource(); -// $requestedSource->setSlug(SystemSlugType::IMPRINT); -// $requestedRight = new Right(); -// $requestedRight->setSource($requestedSource); -// $requestedRight->setLayer(LayerType::SOURCE); -// $requestedRight->setType(CRUDType::READ); -// $sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler()); + // // $response = new Response(); + // // $response->setContent('GET Request!'); -// return $sourceResponseManager->getResponse(); - } + // // return $response; + + // // $requestedSource = new PureSource(); + // // $requestedSource->setSlug(SystemSlugType::IMPRINT); + // // $requestedRight = new Right(); + // // $requestedRight->setSource($requestedSource); + // // $requestedRight->setLayer(LayerType::SOURCE); + // // $requestedRight->setType(CRUDType::READ); + // // $sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler()); + + // // return $sourceResponseManager->getResponse(); +// } /** * @Route("/{_locale}/api/source/{identifier}.{_format}", diff --git a/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUD.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/AbstractSecureCRUD.php similarity index 62% rename from application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUD.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/AbstractSecureCRUD.php index f69ec47..b809845 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/AbstractSecureCRUD.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/AbstractSecureCRUD.php @@ -1,11 +1,9 @@ setText('Hello World!'); + + return $source; + } +} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/SecureCRUDInterface.php similarity index 66% rename from application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDInterface.php rename to application/symfony/src/Domain/SecureCRUDManagement/CRUD/SecureCRUDInterface.php index d630354..0da3f66 100644 --- a/application/symfony/src/Domain/SecureCRUDManagement/SecureCRUDInterface.php +++ b/application/symfony/src/Domain/SecureCRUDManagement/CRUD/SecureCRUDInterface.php @@ -1,6 +1,6 @@ setText('Hello World!'); - - return $source; - } -} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php deleted file mode 100644 index 0dc723f..0000000 --- a/application/symfony/src/Domain/SecureCRUDManagement/Create/SecureSourceCreatorInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -getCrud($crud); + } + + /** + * @param string $layer + * + * @return string + */ + protected 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) + { + $this->request = $requestStack->getCurrentRequest(); + $this->security = $security; + } +} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php new file mode 100644 index 0000000..7b216d1 --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCRUDFactoryServiceInterface.php @@ -0,0 +1,17 @@ +getLayer()) { + case LayerType::SOURCE: + return new SecureSourceCreator($this->request, $this->security); + case LayerType::MEMBER: + } + } +} diff --git a/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceInterface.php b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceInterface.php new file mode 100644 index 0000000..484835c --- /dev/null +++ b/application/symfony/src/Domain/SecureCRUDManagement/Factory/SecureCreatorFactoryServiceInterface.php @@ -0,0 +1,10 @@ +request = $requestStack->getCurrentRequest(); - $this->security = $security; - } - - /** - * @param RightInterface $requestedRight - */ - public function create(?RightInterface $requestedRight = null) - { - return new SecureSourceCreator($this->request, $this->security); - } -} diff --git a/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryServiceTest.php b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryServiceTest.php new file mode 100644 index 0000000..1bd8371 --- /dev/null +++ b/application/symfony/tests/Unit/Domain/SecureCRUDManagement/Factory/AbstractSecureCRUDFactoryServiceTest.php @@ -0,0 +1,34 @@ +getCRUDNamespace($layer, $crud); + } + + public function create(RightInterface $requestedRight): SecureCreatorInterface + { + } + }; + $result = $abstractSecureCRUDFactoryService->publicGetCRUDNamespace('Layer', 'Crud'); + $this->assertEquals('App\\Domain\\SecureCRUDManagement\\CRUD\\Crud\\SecureLayerCrud', $result); + } +}