mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Refactored code and implemented parts of AccessManagement
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user