Optimized logic for source.html.twig

This commit is contained in:
Kevin Frantz
2019-02-18 22:58:42 +01:00
parent c702ddf211
commit 15f9925e66
4 changed files with 62 additions and 43 deletions

View File

@@ -9,6 +9,11 @@ use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
*/
class TemplateNameService implements TemplateNameServiceInterface
{
/**
* @var unknown
*/
const BASE_TEMPLATE_DIR = __DIR__.'/../../../templates/';
/**
* @var string The namespace which should be ignored
*/
@@ -71,7 +76,7 @@ class TemplateNameService implements TemplateNameServiceInterface
$origineClass = $this->getClass();
$baseReplaced = str_replace(self::BASE_NAMESPACE, self::BASE_ENTITY_TEMPLATE_FOLDER, $origineClass);
$elements = explode('\\', $baseReplaced);
array_pop($elements); //Removes class name
array_pop($elements); // Removes class name
$templatePath = implode('/', $elements);
$lowerCasePath = strtolower($templatePath);
@@ -130,4 +135,29 @@ class TemplateNameService implements TemplateNameServiceInterface
{
return $this->getTemplatePath(self::MOLECULE_PRAEFFIX);
}
private function templateExists(string $template): bool
{
return file_exists(self::BASE_TEMPLATE_DIR.$template);
}
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TemplateManagement\TemplateNameServiceInterface::doesAtomTemplateExists()
*/
public function doesAtomTemplateExist(): bool
{
return $this->templateExists($this->getAtomTemplateName());
}
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TemplateManagement\TemplateNameServiceInterface::doesMoleculeTemplateExists()
*/
public function doesMoleculeTemplateExist(): bool
{
return $this->templateExists($this->getMoleculeTemplateName());
}
}

View File

@@ -16,4 +16,14 @@ interface TemplateNameServiceInterface
* @return string a template without a frame
*/
public function getAtomTemplateName(): string;
/**
* @return bool True if template exists
*/
public function doesAtomTemplateExist(): bool;
/**
* @return bool True if template exists
*/
public function doesMoleculeTemplateExist(): bool;
}