mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized SecureCRUDFactory
This commit is contained in:
@@ -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
|
||||
{
|
||||
}
|
@@ -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
|
@@ -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
|
||||
{
|
@@ -7,7 +7,7 @@ use App\Entity\EntityInterface;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class SecureMemberCreator extends AbstractSecureCreator
|
||||
final class SecureMemberCreate extends AbstractSecureCreate
|
||||
{
|
||||
public function create(): EntityInterface
|
||||
{
|
@@ -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
|
||||
{
|
@@ -10,7 +10,7 @@ use App\Entity\Source\Primitive\Text\TextSource;
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
final class SecureSourceCreator extends AbstractSecureCreator
|
||||
final class SecureSourceCreate extends AbstractSecureCreate
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface;
|
||||
use App\DBAL\Types\Meta\Right\CRUDType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
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}
|
||||
*
|
||||
* @see \App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface::create()
|
||||
*/
|
||||
public function create(RightInterface $requestedRight): SecureCreatorInterface
|
||||
{
|
||||
$namespace = $this->getCRUDNamespace($requestedRight->getLayer(), self::CRUD_TYPE);
|
||||
|
||||
return new $namespace($this->request, $this->security);
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Factory;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SecureCreatorFactoryServiceInterface extends SecureCRUDFactoryServiceInterface
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user