Optimized Template Management and implemented TemplateNameService

This commit is contained in:
Kevin Frantz
2019-02-15 16:55:49 +01:00
parent b0d57e41f3
commit 3e1590ffbf
13 changed files with 301 additions and 28 deletions

View File

@@ -0,0 +1,107 @@
<?php
namespace App\Domain\TemplateManagement;
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
/**
* @author kevinfrantz
*/
final class TemplateNameService implements TemplateNameServiceInterface
{
/**
* @var string The namespace which should be ignored
*/
const BASE_NAMESPACE = 'App\\Entity';
/**
* @var string the basic entry point for templates
*/
const BASE_ENTITY_TEMPLATE_FOLDER = 'entity';
/**
* @var string
*/
const MOLECULE_PRAEFFIX = '';
/**
* @var string
*/
const ATOM_PRAEFFIX = '_';
/**
* @var string
*/
const TWIG_SUFFIX = '.html.twig';
/**
* @var RequestedActionServiceInterface
*/
private $requestedActionService;
/**
* @param RequestedActionServiceInterface $requestedActionService
*/
public function __construct(RequestedActionServiceInterface $requestedActionService)
{
$this->requestedActionService = $requestedActionService;
}
/**
* @return string
*/
private function getBasePath(): string
{
$origineClass = $this->requestedActionService->getRequestedEntity()->getClass();
$baseReplaced = str_replace(self::BASE_NAMESPACE, self::BASE_ENTITY_TEMPLATE_FOLDER, $origineClass);
$elements = explode('\\', $baseReplaced);
array_pop($elements); //Removes class name
$templatePath = implode('/', $elements);
$lowerCasePath = strtolower($templatePath);
return $lowerCasePath.'/';
}
/**
* @return string the short class name in lower cases
*/
private function getShortName(): string
{
$origineClass = $this->requestedActionService->getRequestedEntity()->getClass();
$elements = explode('\\', $origineClass);
$class = $elements[count($elements) - 1];
$lcFirst = lcfirst($class);
$bigLettersSubstituted = preg_replace('/([A-Z])/', '_$1', $lcFirst);
$lowerCase = strtolower($bigLettersSubstituted);
return $lowerCase;
}
/**
* @return string
*/
private function getActionSuffix(): string
{
return '_'.strtolower($this->requestedActionService->getActionType());
}
/**
* @param string $type
*
* @return string
*/
private function getTemplatePath(?string $type): string
{
return $this->getBasePath().$type.$this->getShortName().$this->getActionSuffix().self::TWIG_SUFFIX;
}
public function getAtomTemplateName(): string
{
return $this->getTemplatePath(self::ATOM_PRAEFFIX);
}
public function getMoleculeTemplateName(): string
{
return $this->getTemplatePath(self::MOLECULE_PRAEFFIX);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Domain\TemplateManagement;
/**
* @author kevinfrantz
*/
interface TemplateNameServiceInterface
{
/**
* @return string A template inclusiv frame. (Standalone)
*/
public function getMoleculeTemplateName(): string;
/**
* @return string a template without a frame
*/
public function getAtomTemplateName(): string;
}

View File

@@ -6,6 +6,9 @@ use App\DBAL\Types\RESTResponseType;
/**
* @author kevinfrantz
*
* @deprecated
* @see TemplatePathService
*/
final class TemplatePathInformation implements TemplatePathInformationInterface
{

View File

@@ -8,6 +8,9 @@ use App\DBAL\Types\RESTResponseType;
* Manages all informations which are needed to process templates.
*
* @author kevinfrantz
*
* @deprecated
* @see TemplatePathServiceInterface
*/
interface TemplatePathInformationInterface extends ReloadTypeInterface
{