AbstractType::class, ActionType::READ => EntityInterface::class, // Mayber change this to refection later! ActionType::UPDATE => AbstractAction::class, ActionType::DELETE => EntityInterface::class, ActionType::EXECUTE => EntityInterface::class, // This is just a dummy value to pass tests. Substitute it! ]; /** * @var ArrayCollection */ private $actionDataMap; /** * @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::getChoices())) { 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 intance doesn\'t map to <<$instance>>."); } public function __construct() { $this->actionDataMap = 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->actionDataMap->set($actionType, $data); } /** * {@inheritdoc} * * @see \Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface::getActionTemplateData() */ public function getData(string $actionType) { if ($this->isValidActionType($actionType) && $this->isDataStored($actionType)) { return $this->actionDataMap->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->actionDataMap->containsKey($actionType); } }