Implemented ActionTemplateDataStoreService in MVC and template

This commit is contained in:
Kevin Frantz 2019-02-19 21:08:29 +01:00
parent 472eb60fd5
commit 9862bc493c
8 changed files with 56 additions and 40 deletions

View File

@ -6,4 +6,5 @@ twig:
globals:
layer_action_map: "@Infinito\\Domain\\LayerManagement\\LayerActionMap"
action_icon_class_map: "@Infinito\\Domain\\TwigManagement\\ActionIconClassMap"
action_template_name_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateNameServiceInterface"
action_template_name_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateNameServiceInterface"
action_template_data_store_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateDataStoreServiceInterface"

View File

@ -3,15 +3,19 @@
namespace Infinito\Domain\MVCManagement;
use FOS\RestBundle\View\View;
use Infinito\Entity\EntityInterface;
use Infinito\Domain\ActionManagement\ActionHandlerServiceInterface;
use Infinito\Domain\TemplateManagement\TemplateNameServiceInterface;
use Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface;
use Infinito\Attribut\ActionTypeAttribut;
use Infinito\DBAL\Types\ActionType;
/**
* @author kevinfrantz
*/
final class MVCRoutineService implements MVCRoutineServiceInterface
{
use ActionTypeAttribut;
/**
* @var ActionHandlerServiceInterface
*/
@ -23,27 +27,30 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
private $templateNameService;
/**
* @param EntityInterface[]|EntityInterface|null $result
*
* @return array Well formated data for view
* @var ActionTemplateDataStoreServiceInterface
*/
private function getViewData($result): array
private $actionTemplateDataStore;
/**
* @return View
*/
private function getView(): View
{
switch (gettype($result)) {
case 'object':
return ['entity' => $result];
case 'null':
return [];
}
$view = View::create();
$view->setTemplate($this->templateNameService->getMoleculeTemplateName());
$view->setData($this->actionTemplateDataStore->getAllStoredData());
return $view;
}
/**
* @param ActionHandlerServiceInterface $actionHandlerService
*/
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService)
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService, ActionTemplateDataStoreServiceInterface $actionTemplateDataStore)
{
$this->actionHandlerService = $actionHandlerService;
$this->templateNameService = $templateNameService;
$this->actionTemplateDataStore = $actionTemplateDataStore;
}
/**
@ -53,24 +60,13 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
*/
public function process(): View
{
$result = $this->actionHandlerService->handle();
$data = $this->getViewData($result);
$view = $this->getView($data);
if (!$this->actionType) {
$result = $this->actionHandlerService->handle();
$this->actionTemplateDataStore->setData(ActionType::READ, $result);
$view = $this->getView();
return $view;
}
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\MVCManagement\MVCRoutineServiceInterface::getView()
*/
public function getView(array $data): View
{
$view = View::create();
$view->setTemplate($this->templateNameService->getMoleculeTemplateName());
$view->setData($data);
return $view;
return $view;
}
throw new \Exception('Not implemented yet!');
}
}

View File

@ -3,13 +3,14 @@
namespace Infinito\Domain\MVCManagement;
use FOS\RestBundle\View\View;
use Infinito\Attribut\ActionTypeAttributInterface;
/**
* This interface offers the options to process an MVC routine.
*
* @author kevinfrantz
*/
interface MVCRoutineServiceInterface
interface MVCRoutineServiceInterface extends ActionTypeAttributInterface
{
/**
* Process through the layers.

View File

@ -12,6 +12,7 @@ use Infinito\Form\AbstractType;
use Infinito\Entity\EntityInterface;
use Infinito\Domain\ActionManagement\AbstractAction;
use Infinito\Exception\NotCorrectInstanceException;
use Doctrine\Common\Collections\Collection;
/**
* @author kevinfrantz
@ -30,9 +31,9 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
];
/**
* @var ArrayCollection
* @var Collection
*/
private $actionDataMap;
private $actionDataStore;
/**
* @param string $actionType
@ -68,7 +69,7 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
public function __construct()
{
$this->actionDataMap = new ArrayCollection();
$this->actionDataStore = new ArrayCollection();
}
/**
@ -81,7 +82,7 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
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);
$this->actionDataStore->set($actionType, $data);
}
/**
@ -92,7 +93,7 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
public function getData(string $actionType)
{
if ($this->isValidActionType($actionType) && $this->isDataStored($actionType)) {
return $this->actionDataMap->get($actionType);
return $this->actionDataStore->get($actionType);
}
throw new NotSetException("The data for the action type <<$actionType>> is not set!");
}
@ -104,6 +105,16 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
*/
public function isDataStored(string $actionType): bool
{
return $this->actionDataMap->containsKey($actionType);
return $this->actionDataStore->containsKey($actionType);
}
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TemplateManagement\ActionTemplateDataStoreServiceInterface::getAllData()
*/
public function getAllStoredData(): Collection
{
return $this->actionDataStore;
}
}

View File

@ -2,6 +2,8 @@
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.
*
@ -30,4 +32,9 @@ interface ActionTemplateDataStoreServiceInterface
* @return bool True if the data is set
*/
public function isDataStored(string $actionType): bool;
/**
* @return Collection
*/
public function getAllStoredData(): Collection;
}

View File

@ -1 +1 @@
{{ entity.text }}
{{ action_template_data_store_service.getData(action).text }}

View File

@ -1,2 +1 @@
{% set source = entity %}
{% extends "entity/source/source.html.twig" %}

View File

@ -1,4 +1,5 @@
{% extends "frames/default.html.twig" %}
{% set entity = action_template_data_store_service.getData('read') %}
{% block title %}
{{ 'Source'|trans }}: {% if entity.hasSlug %}{{ entity.slug }}{% endif %}#{{ entity.id }}
{% endblock %}