mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Implemented draft for ActionManagement
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement;
|
||||
|
||||
use App\Entity\EntityInterface;
|
||||
use App\Exception\NotSecureException;
|
||||
use App\Exception\NotValidByFormException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractAction extends AbstractActionConstructor implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function isSecure(): bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function isValidByForm(): bool;
|
||||
|
||||
/**
|
||||
* Process the routine.
|
||||
*
|
||||
* @return EntityInterface|EntityInterface[]|null
|
||||
*/
|
||||
abstract protected function proccess();
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\ActionInterface::execute()
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ($this->isSecure()) {
|
||||
if ($this->isValidByForm()) {
|
||||
return $this->proccess();
|
||||
}
|
||||
throw new NotValidByFormException('The requested Entity is not valid!');
|
||||
}
|
||||
throw new NotSecureException("You don't have the permission to execute this action!");
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement;
|
||||
|
||||
/**
|
||||
* This class just containes the constructor
|
||||
* It is used by concrete actions and the factory.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractActionConstructor
|
||||
{
|
||||
/**
|
||||
* @var ActionServiceInterface
|
||||
*/
|
||||
protected $actionService;
|
||||
|
||||
/**
|
||||
* @param ActionServiceInterface $actionService
|
||||
*/
|
||||
final public function __construct(ActionServiceInterface $actionService)
|
||||
{
|
||||
$this->actionService = $actionService;
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class ActionFactoryService extends AbstractActionConstructor implements ActionFactoryServiceInterface
|
||||
{
|
||||
const BASE_NAMESPACE = 'App\\Domain\\ActionManagement\\';
|
||||
|
||||
const CLASS_SUFFIX = 'Action';
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function ucfirst(string $name): string
|
||||
{
|
||||
return ucfirst(strtolower($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param string $layer
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getClassName(string $action, string $layer = ''): string
|
||||
{
|
||||
return $this->ucfirst($action).$this->ucfirst($layer).self::CLASS_SUFFIX;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $layer
|
||||
* @param string $action
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getActionNamespace(string $action, string $layer = ''): string
|
||||
{
|
||||
return self::BASE_NAMESPACE.$this->ucfirst($action).'\\'.$this->getClassName($action, $layer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function generateFullClassName(): string
|
||||
{
|
||||
$requestedAction = $this->actionService->getRequestedAction();
|
||||
$action = $requestedAction->getActionType();
|
||||
$layer = $requestedAction->getLayer();
|
||||
$class = $this->getActionNamespace($action, $layer);
|
||||
if (class_exists($class)) {
|
||||
return $class;
|
||||
}
|
||||
$defaultClass = $this->getActionNamespace($action);
|
||||
|
||||
return $defaultClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\ActionFactoryServiceInterface::create()
|
||||
*/
|
||||
public function create(): ActionInterface
|
||||
{
|
||||
$class = $this->generateFullClassName();
|
||||
|
||||
return new $class($this->actionService);
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement;
|
||||
|
||||
/**
|
||||
* Offers a function to create an action object by the RequestedActionService.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface ActionFactoryServiceInterface
|
||||
{
|
||||
/**
|
||||
* @return ActionInterface
|
||||
*/
|
||||
public function create(): ActionInterface;
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement;
|
||||
|
||||
use App\Entity\EntityInterface;
|
||||
|
||||
interface ActionInterface
|
||||
{
|
||||
/**
|
||||
* Executes the action.
|
||||
*
|
||||
* @return EntityInterface|EntityInterface[]|null
|
||||
*/
|
||||
public function execute();
|
||||
}
|
@@ -4,12 +4,25 @@ namespace App\Domain\ActionManagement;
|
||||
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Domain\FormManagement\EntityFormBuilderServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use App\Repository\RepositoryInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class ActionService implements ActionServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $requestStack;
|
||||
|
||||
/**
|
||||
* @var RequestedActionInterface
|
||||
*/
|
||||
@@ -20,13 +33,32 @@ final class ActionService implements ActionServiceInterface
|
||||
*/
|
||||
private $secureRequestedRightChecker;
|
||||
|
||||
/**
|
||||
* @var LayerRepositoryFactoryServiceInterface
|
||||
*/
|
||||
private $layerRepositoryFactoryService;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $entityFormBuilderService;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @param RequestedActionInterface $requestedAction
|
||||
*/
|
||||
public function __construct(RequestedActionInterface $requestedAction, SecureRequestedRightCheckerInterface $secureRequestedRightChecker)
|
||||
public function __construct(RequestedActionInterface $requestedAction, SecureRequestedRightCheckerInterface $secureRequestedRightChecker, RequestStack $requestStack, LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService, EntityFormBuilderServiceInterface $entityFormBuilderService, EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->requestedAction = $requestedAction;
|
||||
$this->secureRequestedRightChecker = $secureRequestedRightChecker;
|
||||
$this->requestStack = $requestStack;
|
||||
$this->layerRepositoryFactoryService = $layerRepositoryFactoryService;
|
||||
$this->entityFormBuilderService = $entityFormBuilderService;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,4 +80,44 @@ final class ActionService implements ActionServiceInterface
|
||||
{
|
||||
return $this->secureRequestedRightChecker->check($this->requestedAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormBuilderInterface
|
||||
*/
|
||||
public function getForm(EntityInterface $entity): FormBuilderInterface
|
||||
{
|
||||
$this->entityFormBuilderService->create($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\ActionServiceInterface::getRequest()
|
||||
*/
|
||||
public function getRequest(): Request
|
||||
{
|
||||
return $this->requestStack->getCurrentRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;inheritDoc}.
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\ActionServiceInterface::getRepository()
|
||||
*/
|
||||
public function getRepository(): RepositoryInterface
|
||||
{
|
||||
$layer = $this->requestedAction->getLayer();
|
||||
|
||||
return $this->layerRepositoryFactoryService->getRepository($layer);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\ActionServiceInterface::getEntityManager()
|
||||
*/
|
||||
public function getEntityManager(): EntityManagerInterface
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,11 @@
|
||||
namespace App\Domain\ActionManagement;
|
||||
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Repository\RepositoryInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* This interface offers all classes for managing an Action.
|
||||
@@ -20,4 +25,26 @@ interface ActionServiceInterface
|
||||
* @return bool true if the action permissions are right
|
||||
*/
|
||||
public function isRequestedActionSecure(): bool;
|
||||
|
||||
/**
|
||||
* @return Request
|
||||
*/
|
||||
public function getRequest(): Request;
|
||||
|
||||
/**
|
||||
* @return RepositoryInterface
|
||||
*/
|
||||
public function getRepository(): RepositoryInterface;
|
||||
|
||||
/**
|
||||
* @param EntityInterface $entity
|
||||
*
|
||||
* @return FormBuilderInterface
|
||||
*/
|
||||
public function getForm(EntityInterface $entity): FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* @return EntityManagerInterface
|
||||
*/
|
||||
public function getEntityManager(): EntityManagerInterface;
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement\Create;
|
||||
|
||||
use App\Domain\ActionManagement\AbstractAction;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractCreateAction extends AbstractAction
|
||||
{
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement\Create;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class CreateSourceAction extends AbstractCreateAction
|
||||
{
|
||||
protected function isSecure(): bool
|
||||
{
|
||||
}
|
||||
|
||||
protected function isValidByForm(): bool
|
||||
{
|
||||
}
|
||||
|
||||
protected function proccess()
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement\Delete;
|
||||
|
||||
use App\Domain\ActionManagement\AbstractAction;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* Declare as not final as soon as you need it!
|
||||
*/
|
||||
final class DeleteAction extends AbstractAction
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::isSecure()
|
||||
*/
|
||||
protected function isSecure(): bool
|
||||
{
|
||||
return $this->isSecure();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement!
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::isValidByForm()
|
||||
*/
|
||||
protected function isValidByForm(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::proccess()
|
||||
*/
|
||||
protected function proccess()
|
||||
{
|
||||
$entityManager = $this->actionService->getEntityManager();
|
||||
$entity = $this->actionService->getRequestedAction()->getRequestedEntity()->getEntity();
|
||||
$entityManager->remove($entity);
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement\Read;
|
||||
|
||||
use App\Domain\ActionManagement\AbstractAction;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class ReadAction extends AbstractAction implements ReadActionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::isSecure()
|
||||
*/
|
||||
protected function isSecure(): bool
|
||||
{
|
||||
return $this->actionService->isRequestedActionSecure();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement!
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::isValidByForm()
|
||||
*/
|
||||
protected function isValidByForm(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::proccess()
|
||||
*/
|
||||
protected function proccess()
|
||||
{
|
||||
return $this->actionService->getRequestedAction()->getRequestedEntity()->getEntity();
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement\Read;
|
||||
|
||||
use App\Domain\ActionManagement\ActionInterface;
|
||||
|
||||
/**
|
||||
* Needed for mocking with PHPUnit!
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface ReadActionInterface extends ActionInterface
|
||||
{
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ActionManagement\Update;
|
||||
|
||||
class UpdateSourceAction
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user