mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized logic for source.html.twig
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user