Optimized view generation process

This commit is contained in:
Kevin Frantz
2019-03-28 13:26:40 +01:00
parent 4a129b172b
commit 13b45b31ae
8 changed files with 44 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ use FOS\RestBundle\View\View;
use Infinito\Domain\RequestManagement\Action\RequestedActionInterface;
use Infinito\Domain\ActionManagement\ActionServiceInterface;
use Infinito\Domain\ActionManagement\ActionFactoryServiceInterface;
use Infinito\Domain\TemplateManagement\TemplateNameServiceInterface;
/**
* @author kevinfrantz
@@ -27,14 +28,37 @@ final class ViewBuilder implements ViewBuilderInterface
*/
private $actionFactoryService;
/**
* @var TemplateNameServiceInterface
*/
private $templateNameService;
/**
* Don't know if this function will be usefull in the future.
* Feel free to remove it if this should not be the case.
*
* @todo Implement tests
*
* @return string The general entity template or a individual template if it is set
*/
private function getTemplate(): string
{
if ($this->templateNameService->doesMoleculeTemplateExist()) {
return $this->templateNameService->getMoleculeTemplateName();
}
return self::TWIG_ENTITY_TEMPLATE_PATH;
}
/**
* @param ActionServiceInterface $actionService
* @param ActionFactoryServiceInterface $actionFactoryService
*/
public function __construct(ActionServiceInterface $actionService, ActionFactoryServiceInterface $actionFactoryService)
public function __construct(ActionServiceInterface $actionService, ActionFactoryServiceInterface $actionFactoryService, TemplateNameServiceInterface $templateNameService)
{
$this->view = new View();
$this->view = View::create();
$this->actionService = $actionService;
$this->templateNameService = $templateNameService;
}
/**
@@ -42,10 +66,10 @@ final class ViewBuilder implements ViewBuilderInterface
*/
public function getView(): View
{
$view = View::create();
$view->setTemplate(self::TWIG_ENTITY_TEMPLATE_PATH);
$template = $this->getTemplate();
$this->view->setTemplate($template);
return $view;
return $this->view;
}
/**