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

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

View File

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

View File

@ -12,6 +12,7 @@ use Infinito\Form\AbstractType;
use Infinito\Entity\EntityInterface; use Infinito\Entity\EntityInterface;
use Infinito\Domain\ActionManagement\AbstractAction; use Infinito\Domain\ActionManagement\AbstractAction;
use Infinito\Exception\NotCorrectInstanceException; use Infinito\Exception\NotCorrectInstanceException;
use Doctrine\Common\Collections\Collection;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -30,9 +31,9 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
]; ];
/** /**
* @var ArrayCollection * @var Collection
*/ */
private $actionDataMap; private $actionDataStore;
/** /**
* @param string $actionType * @param string $actionType
@ -68,7 +69,7 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
public function __construct() 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)) { if ($this->isValidActionType($actionType) && $this->isValidActionData($actionType, $data) && $this->isDataStored($actionType)) {
throw new AllreadySetException("The data for the action type <<$actionType>> is allready set!"); 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) public function getData(string $actionType)
{ {
if ($this->isValidActionType($actionType) && $this->isDataStored($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!"); 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 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; 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. * 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 * @return bool True if the data is set
*/ */
public function isDataStored(string $actionType): bool; 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" %} {% extends "entity/source/source.html.twig" %}

View File

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