mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-10 06:27:24 +01:00
Optimized SecureCRUDManagement Draft
This commit is contained in:
parent
f2828e0d5e
commit
6b29c5a577
@ -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
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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}",
|
||||
|
@ -1,11 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement;
|
||||
namespace App\Domain\SecureCRUDManagement\CRUD;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
abstract class AbstractSecureCRUD implements SecureCRUDInterface
|
||||
{
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
|
||||
|
||||
use App\Domain\SecureCRUDManagement\AbstractSecureCRUD;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractSecureCreator extends AbstractSecureCRUD implements SecureCreatorInterface
|
||||
{
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
|
||||
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDInterface;
|
||||
use App\Entity\EntityInterface;
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
|
||||
|
||||
use App\Domain\SecureCRUDManagement\Create\AbstractSecureCreator;
|
||||
use App\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class SecureMemberCreator extends AbstractSecureCreator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SecureCRUDManagement\Create\SecureCreatorInterface::create()
|
||||
*/
|
||||
public function create(): EntityInterface
|
||||
{
|
||||
//todo implement!
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
|
||||
|
||||
use App\Entity\EntityInterface;
|
||||
use App\Entity\Source\Primitive\Text\TextSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
final class SecureSourceCreator extends AbstractSecureCreator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface::create()
|
||||
*/
|
||||
public function create(): EntityInterface
|
||||
{
|
||||
$source = new TextSource();
|
||||
$source->setText('Hello World!');
|
||||
|
||||
return $source;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement;
|
||||
namespace App\Domain\SecureCRUDManagement\CRUD;
|
||||
|
||||
/**
|
||||
* @todo Implement!
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
abstract class AbstractSecureCreator implements SecureCreatorInterface
|
||||
{
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
|
||||
use App\Entity\EntityInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use App\Entity\Source\Primitive\Text\TextSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
class SecureSourceCreator extends AbstractSecureCreator implements SecureSourceCreatorInterface
|
||||
{
|
||||
public function __construct(Request $request, Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
public function create(): EntityInterface
|
||||
{
|
||||
$source = new TextSource();
|
||||
$source->setText('Hello World!');
|
||||
|
||||
return $source;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
interface SecureSourceCreatorInterface extends SecureCreatorInterface
|
||||
{
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
* @todo substitute through child classes!
|
||||
*/
|
||||
abstract class AbstractSecureCRUDFactoryService implements SecureCRUDFactoryServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var Security
|
||||
*/
|
||||
protected $security;
|
||||
|
||||
/**
|
||||
* @param string $crud
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCrud(string $crud): string
|
||||
{
|
||||
return ucfirst(strtolower($crud));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $layer
|
||||
* @param string $crud
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getClassName(string $layer, string $crud): string
|
||||
{
|
||||
return 'Secure'.ucfirst(strtolower($layer)).$this->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;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SecureCRUDFactoryServiceInterface
|
||||
{
|
||||
/**
|
||||
* @return SecureCreatorInterface
|
||||
*/
|
||||
public function create(RightInterface $requestedRight): SecureCreatorInterface;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
final class SecureCreatorFactoryService extends AbstractSecureCRUDFactoryService
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface::create()
|
||||
*/
|
||||
public function create(RightInterface $requestedRight): SecureCreatorInterface
|
||||
{
|
||||
switch ($requestedRight->getLayer()) {
|
||||
case LayerType::SOURCE:
|
||||
return new SecureSourceCreator($this->request, $this->security);
|
||||
case LayerType::MEMBER:
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SecureCreatorFactoryServiceInterface extends SecureCRUDFactoryServiceInterface
|
||||
{
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Domain\SecureCRUDManagement\Create\SecureSourceCreator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
* @todo substitute through child classes!
|
||||
*/
|
||||
class SecureCRUDFactoryService
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var Security
|
||||
*/
|
||||
private $security;
|
||||
|
||||
public function __construct(RequestStack $requestStack, Security $security)
|
||||
{
|
||||
$this->request = $requestStack->getCurrentRequest();
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RightInterface $requestedRight
|
||||
*/
|
||||
public function create(?RightInterface $requestedRight = null)
|
||||
{
|
||||
return new SecureSourceCreator($this->request, $this->security);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Domain\SecureCRUDManagement\Factory\AbstractSecureCRUDFactoryService;
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class AbstractSecureCRUDFactoryServiceTest extends TestCase
|
||||
{
|
||||
public function testGetCRUDNamespace(): void
|
||||
{
|
||||
$abstractSecureCRUDFactoryService = new class() extends AbstractSecureCRUDFactoryService {
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function publicGetCRUDNamespace(string $layer, string $crud): string
|
||||
{
|
||||
return $this->getCRUDNamespace($layer, $crud);
|
||||
}
|
||||
|
||||
public function create(RightInterface $requestedRight): SecureCreatorInterface
|
||||
{
|
||||
}
|
||||
};
|
||||
$result = $abstractSecureCRUDFactoryService->publicGetCRUDNamespace('Layer', 'Crud');
|
||||
$this->assertEquals('App\\Domain\\SecureCRUDManagement\\CRUD\\Crud\\SecureLayerCrud', $result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user