mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Refactored code and implemented parts of AccessManagement
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
namespace Infinito\Domain\ActionManagement\Create;
|
||||
|
||||
use Infinito\Domain\SourceManagement\SourceClassInformationService;
|
||||
use Infinito\Form\Source\SourceType;
|
||||
use Infinito\Entity\Source\AbstractSource;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Infinito\Domain\ParameterManagement\Parameter\ClassParameter;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -32,7 +32,7 @@ final class CreateSourceAction extends AbstractCreateAction
|
||||
private function setSourceClass(): void
|
||||
{
|
||||
$request = $this->actionService->getRequest();
|
||||
$this->sourceClass = $request->get(SourceType::CLASS_PARAMETER_NAME, self::DEFAULT_CLASS);
|
||||
$this->sourceClass = $request->get(ClassParameter::getKey(), self::DEFAULT_CLASS);
|
||||
}
|
||||
|
||||
private function setForm(): void
|
||||
|
@@ -11,6 +11,7 @@ use Infinito\DBAL\Types\ActionType;
|
||||
use Infinito\Exception\NotCorrectInstanceException;
|
||||
use Infinito\Entity\EntityInterface;
|
||||
use Infinito\Logic\Result\ResultInterface;
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -22,49 +23,6 @@ final class ActionsResultsDAOService extends AbstractActionsDAO implements Actio
|
||||
*/
|
||||
private $processedData;
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @throws NoValidChoiceException
|
||||
*/
|
||||
private function throwNoValidActionTypeException(string $actionType): void
|
||||
{
|
||||
throw new NoValidChoiceException("The action type <<$actionType>> is not defined and not valid!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @throws NoValidChoiceException For false a exception is thrown
|
||||
*
|
||||
* @return bool Everytime True
|
||||
*/
|
||||
private function isValidActionType(string $actionType): bool
|
||||
{
|
||||
if (in_array($actionType, ActionType::getValues())) {
|
||||
return true;
|
||||
}
|
||||
$this->throwNoValidActionTypeException($actionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function describes which data is expected.
|
||||
*
|
||||
* @param string $actionType
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws NotCorrectInstanceException For false a exception is thrown
|
||||
*
|
||||
* @return bool Everytime True
|
||||
*/
|
||||
private function validateActionData(string $actionType, $data): bool
|
||||
{
|
||||
if ($this->isValidActionData($actionType)) {
|
||||
return true;
|
||||
}
|
||||
throw new NotCorrectInstanceException('Data <<'.($data).">> for action type <<$actionType>> is not valid!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
* @param EntityInterface|ResultInterface|null $data
|
||||
@@ -84,7 +42,76 @@ final class ActionsResultsDAOService extends AbstractActionsDAO implements Actio
|
||||
case ActionType::EXECUTE:
|
||||
return $data instanceof ResultInterface;
|
||||
}
|
||||
$this->throwNoValidActionTypeException($actionType);
|
||||
throw new NotImplementedException("The ActionType <<$actionType>> is not implemented in <<".__CLASS__.':'.__FUNCTION__.'>>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @throws NoValidChoiceException
|
||||
*/
|
||||
private function throwNoValidActionTypeException(string $actionType): void
|
||||
{
|
||||
throw new NoValidChoiceException("The action type <<$actionType>> is not defined and not valid!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidActionType(string $actionType): bool
|
||||
{
|
||||
return in_array($actionType, ActionType::getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*/
|
||||
private function validateActionType(string $actionType): void
|
||||
{
|
||||
if (!$this->isValidActionType($actionType)) {
|
||||
$this->throwNoValidActionTypeException($actionType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function describes which data is expected.
|
||||
*
|
||||
* @param string $actionType
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws NotCorrectInstanceException For false a exception is thrown
|
||||
*/
|
||||
private function validateActionData(string $actionType, $data): void
|
||||
{
|
||||
if (!$this->isValidActionData($actionType, $data)) {
|
||||
throw new NotCorrectInstanceException('Data <<'.gettype($data).(is_object($data) ? ':'.get_class($data) : '').">> is not valid for action type <<$actionType>>!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @throws NotSetException
|
||||
*/
|
||||
private function validateNotSet(string $actionType): void
|
||||
{
|
||||
if ($this->isDataStored($actionType)) {
|
||||
throw new AllreadySetException("Data for <<$actionType>> is allready stored.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @throws NotSetException
|
||||
*/
|
||||
private function validateSet(string $actionType): void
|
||||
{
|
||||
if (!$this->isDataStored($actionType)) {
|
||||
throw new NotSetException("No data for <<$actionType>> is stored.");
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
@@ -109,9 +136,9 @@ final class ActionsResultsDAOService extends AbstractActionsDAO implements Actio
|
||||
*/
|
||||
public function setData(string $actionType, $data): void
|
||||
{
|
||||
if ($this->isValidActionType($actionType) && $this->validateActionData($actionType, $data) && $this->isDataStored($actionType)) {
|
||||
throw new AllreadySetException("The data for the action type <<$actionType>> is allready set!");
|
||||
}
|
||||
$this->validateActionType($actionType);
|
||||
$this->validateActionData($actionType, $data);
|
||||
$this->validateNotSet($actionType);
|
||||
$this->processedData->set($actionType, $data);
|
||||
}
|
||||
|
||||
@@ -132,9 +159,9 @@ final class ActionsResultsDAOService extends AbstractActionsDAO implements Actio
|
||||
*/
|
||||
public function getData(string $actionType)
|
||||
{
|
||||
if ($this->isValidActionType($actionType) && $this->isDataStored($actionType)) {
|
||||
return $this->processedData->get($actionType);
|
||||
}
|
||||
throw new NotSetException("The data for the action type <<$actionType>> is not set!");
|
||||
$this->validateActionType($actionType);
|
||||
$this->validateSet($actionType);
|
||||
|
||||
return $this->processedData->get($actionType);
|
||||
}
|
||||
}
|
||||
|
@@ -46,9 +46,18 @@ final class ActionsViewsDAOService extends AbstractActionsDAO implements Actions
|
||||
$viewData = $this->getData($key);
|
||||
$storedData->set($key, $viewData);
|
||||
}
|
||||
|
||||
return $storedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement the mapping
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\DataAccessManagement\ActionsDAOInterface::getData()
|
||||
*/
|
||||
public function getData(string $actionType)
|
||||
{
|
||||
return $this->actionsResultsDAO->getData($actionType);
|
||||
}
|
||||
}
|
||||
|
@@ -13,9 +13,9 @@ final class FormClassNameService implements FormClassNameServiceInterface
|
||||
const ENTITY_BASE_PATH = 'Infinito\\Entity';
|
||||
|
||||
/**
|
||||
* @var string Folder in which the forms are stored
|
||||
* @var string Folder in which the forms for entities are stored
|
||||
*/
|
||||
const FORM_BASE_PATH = 'Infinito\\Form';
|
||||
const FORM_ENTITY_BASE_PATH = 'Infinito\\Form\\Entity';
|
||||
|
||||
/**
|
||||
* @var string Suffix to identifie form classes
|
||||
@@ -29,7 +29,7 @@ final class FormClassNameService implements FormClassNameServiceInterface
|
||||
*/
|
||||
public function getClass(string $origineClass, string $type = ''): string
|
||||
{
|
||||
$replaced = str_replace(self::ENTITY_BASE_PATH, self::FORM_BASE_PATH, $origineClass);
|
||||
$replaced = str_replace(self::ENTITY_BASE_PATH, self::FORM_ENTITY_BASE_PATH, $origineClass);
|
||||
$withType = $replaced.ucfirst($type);
|
||||
$withSuffix = $withType.self::SUFFIX;
|
||||
|
||||
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement\Parameter;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class ClassParameter extends AbstractParameter
|
||||
{
|
||||
/**
|
||||
* @todo Implement type validation
|
||||
*/
|
||||
protected $value = null;
|
||||
}
|
@@ -8,8 +8,8 @@ use Infinito\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface
|
||||
use Infinito\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
|
||||
use Infinito\Domain\ActionManagement\ActionHandlerServiceInterface;
|
||||
use Infinito\Domain\TemplateManagement\TemplateNameServiceInterface;
|
||||
use Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Domain\DataAccessManagement\ActionsResultsDAOServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -37,9 +37,9 @@ final class ProcessService implements ProcessServiceInterface
|
||||
private $templateNameService;
|
||||
|
||||
/**
|
||||
* @var ActionTemplateDataStoreServiceInterface
|
||||
* @var ActionsResultsDAOServiceInterface
|
||||
*/
|
||||
private $actionTemplateDataStore;
|
||||
private $actionsResultsDAOService;
|
||||
|
||||
/**
|
||||
* @var RequestedActionFormBuilderServiceInterface
|
||||
@@ -49,16 +49,16 @@ final class ProcessService implements ProcessServiceInterface
|
||||
/**
|
||||
* @param ActionHandlerServiceInterface $actionHandlerService
|
||||
* @param TemplateNameServiceInterface $templateNameService
|
||||
* @param ActionTemplateDataStoreServiceInterface $actionTemplateDataStore
|
||||
* @param ActionsResultsDAOServiceInterface $actionTemplateDataStore
|
||||
* @param RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService
|
||||
* @param RequestedActionServiceInterface $requestedActionService
|
||||
* @param SecureRequestedRightCheckerServiceInterface $secureRequestedRightCheckerService
|
||||
*/
|
||||
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService, ActionTemplateDataStoreServiceInterface $actionTemplateDataStore, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, RequestedActionServiceInterface $requestedActionService, SecureRequestedRightCheckerServiceInterface $secureRequestedRightCheckerService)
|
||||
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService, ActionsResultsDAOServiceInterface $actionTemplateDataStore, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, RequestedActionServiceInterface $requestedActionService, SecureRequestedRightCheckerServiceInterface $secureRequestedRightCheckerService)
|
||||
{
|
||||
$this->actionHandlerService = $actionHandlerService;
|
||||
$this->templateNameService = $templateNameService;
|
||||
$this->actionTemplateDataStore = $actionTemplateDataStore;
|
||||
$this->actionsResultsDAOService = $actionTemplateDataStore;
|
||||
$this->requestedActionFormBuilderService = $requestedActionFormBuilderService;
|
||||
$this->requestedActionService = $requestedActionService;
|
||||
$this->secureRequestedRightCheckerService = $secureRequestedRightCheckerService;
|
||||
@@ -77,7 +77,7 @@ final class ProcessService implements ProcessServiceInterface
|
||||
// $this->requestedActionService->setActionType(ActionType::READ);
|
||||
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
|
||||
$read = $this->actionHandlerService->handle();
|
||||
$this->actionTemplateDataStore->setData(ActionType::READ, $read);
|
||||
$this->actionsResultsDAOService->setData(ActionType::READ, $read);
|
||||
}
|
||||
// $this->requestedActionService->setActionType(ActionType::UPDATE);
|
||||
// UPDATE VIEW
|
||||
@@ -88,14 +88,15 @@ final class ProcessService implements ProcessServiceInterface
|
||||
// DELETE VIEW
|
||||
// EXECUTE VIEW
|
||||
} else {
|
||||
// @todo move to view
|
||||
// CREATE
|
||||
$this->requestedActionService->getRequestedEntity()->setClass(TextSource::class);
|
||||
$updateForm = $this->requestedActionFormBuilderService->createByService()
|
||||
->getForm()
|
||||
->createView();
|
||||
$this->actionTemplateDataStore->setData(ActionType::CREATE, $updateForm);
|
||||
//$this->requestedActionService->getRequestedEntity()->setClass(TextSource::class);
|
||||
// $updateForm = $this->requestedActionFormBuilderService->createByService()
|
||||
// ->getForm()
|
||||
// ->createView();
|
||||
//$this->actionsResultsDAOService->setData(ActionType::CREATE, $updateForm);
|
||||
}
|
||||
|
||||
return $this->actionTemplateDataStore;
|
||||
return $this->actionsResultsDAOService;
|
||||
}
|
||||
}
|
||||
|
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\TemplateManagement;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Infinito\Exception\AllreadySetException;
|
||||
use Infinito\Exception\NotSetException;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
use Infinito\Exception\NotDefinedException;
|
||||
use Infinito\Exception\NoValidChoiceException;
|
||||
use Infinito\Entity\EntityInterface;
|
||||
use Infinito\Exception\NotCorrectInstanceException;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Component\Form\FormView;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo rename to ActionViewsDAO and move to DataAccessManagement
|
||||
*/
|
||||
final class ActionTemplateDataStoreService implements ActionTemplateDataStoreServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var array|string[] Maps the action to an return type
|
||||
*/
|
||||
const ACTION_DATA_MAPPING = [
|
||||
ActionType::CREATE => FormView::class,
|
||||
ActionType::READ => EntityInterface::class, // Mayber change this to refection later!
|
||||
ActionType::UPDATE => FormView::class,
|
||||
ActionType::DELETE => EntityInterface::class,
|
||||
ActionType::EXECUTE => EntityInterface::class, // This is just a dummy value to pass tests. Substitute it!
|
||||
];
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
private $actionDataStore;
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @throws NotDefinedException For false a exception is thrown
|
||||
*
|
||||
* @return bool Everytime True
|
||||
*/
|
||||
private function isValidActionType(string $actionType): bool
|
||||
{
|
||||
if (in_array($actionType, ActionType::getValues())) {
|
||||
return true;
|
||||
}
|
||||
throw new NoValidChoiceException("The action type <<$actionType>> is not defined and not valid!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws NotCorrectInstanceException For false a exception is thrown
|
||||
*
|
||||
* @return bool Everytime True
|
||||
*/
|
||||
private function isValidActionData(string $actionType, $data): bool
|
||||
{
|
||||
$instance = self::ACTION_DATA_MAPPING[$actionType];
|
||||
if ($data instanceof $instance) {
|
||||
return true;
|
||||
}
|
||||
throw new NotCorrectInstanceException('The data class <<'.get_class($data).">> for action type <<$actionType>> doesn't map to instance <<$instance>>.");
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionDataStore = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface::setActionTemplateData()
|
||||
*/
|
||||
public function setData(string $actionType, $data): void
|
||||
{
|
||||
if ($this->isValidActionType($actionType) && $this->isValidActionData($actionType, $data) && $this->isDataStored($actionType)) {
|
||||
throw new AllreadySetException("The data for the action type <<$actionType>> is allready set!");
|
||||
}
|
||||
$this->actionDataStore->set($actionType, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface::getActionTemplateData()
|
||||
*/
|
||||
public function getData(string $actionType)
|
||||
{
|
||||
if ($this->isValidActionType($actionType) && $this->isDataStored($actionType)) {
|
||||
return $this->actionDataStore->get($actionType);
|
||||
}
|
||||
throw new NotSetException("The data for the action type <<$actionType>> is not set!");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface::isActionTemplateDataSet()
|
||||
*/
|
||||
public function isDataStored(string $actionType): bool
|
||||
{
|
||||
return $this->actionDataStore->containsKey($actionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface::getAllData()
|
||||
*/
|
||||
public function getAllStoredData(): Collection
|
||||
{
|
||||
return $this->actionDataStore;
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\TemplateManagement;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* This class offers a temporary data store to pass data from the controller logic to the template.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Data_store
|
||||
*/
|
||||
interface ActionTemplateDataStoreServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param string $actionType
|
||||
* @param mixed $data The data which a Template needs to be handled
|
||||
*/
|
||||
public function setData(string $actionType, $data): void;
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @return mixed The needed data
|
||||
*/
|
||||
public function getData(string $actionType);
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @return bool True if the data is set
|
||||
*/
|
||||
public function isDataStored(string $actionType): bool;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllStoredData(): Collection;
|
||||
}
|
Reference in New Issue
Block a user