Skip to content

Commit

Permalink
OXDEV-6895 change template filename resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle72 committed Nov 28, 2023
1 parent c5dc25e commit 7f71cbc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 20 deletions.
1 change: 0 additions & 1 deletion services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ services:
class: OxidEsales\Twig\TwigEngine
arguments:
$engine: '@twig'
$fileExtension: '%oxid_esales.templating.engine_template_extension%'
$twigExtensions: !tagged twig.extension
$twigEscaper: !tagged twig.escaper
public: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ class TemplateTypeFactory implements TemplateTypeFactoryInterface
private const BASE_TEMPLATE_TYPE_PATTERN = '%^(?:@([^\s/]+)/)?(.*)$%';

public function __construct(
private TemplateFileResolverInterface $templateFileResolver,
) {
}

public function createFromTemplateName(string $templateName): TemplateTypeInterface
{
$templateName = $this->getFullNameWithFileExtension($templateName);
$this->validateTemplateFilename($templateName);

if ($this->isModuleExtensionFullyQualifiedName($templateName)) {
Expand Down Expand Up @@ -94,11 +92,6 @@ private function isShopNamespace(string $namespace): bool
return !$namespace || $namespace === FilesystemLoader::MAIN_NAMESPACE;
}

private function getFullNameWithFileExtension(string $templateName): string
{
return $this->templateFileResolver->getFilename($templateName);
}

private function validateTemplateFilename(string $templateName): void
{
if (!str_ends_with($templateName, self::TWIG_FILE_EXTENSION)) {
Expand Down
11 changes: 1 addition & 10 deletions src/TwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class TwigEngine implements TemplateEngineInterface
{
public function __construct(
private Environment $engine,
private string $fileExtension,
private TemplateChainResolverInterface $templateChainResolver,
iterable $twigExtensions = [],
iterable $twigEscaper = []
Expand Down Expand Up @@ -67,7 +66,7 @@ public function render(string $name, array $context = []): string
*/
public function exists(string $name): bool
{
return $this->engine->getLoader()->exists($name . '.' . $this->fileExtension);
return $this->engine->getLoader()->exists($name);
}

/**
Expand Down Expand Up @@ -95,19 +94,11 @@ public function addGlobal(string $name, $value)
$this->engine->addGlobal($name, $value);
}

/**
* Returns assigned globals.
*
* @return array
*/
public function getGlobals(): array
{
return $this->engine->getGlobals();
}

/**
* @param EscaperInterface $escaper
*/
public function addEscaper(EscaperInterface $escaper)
{
/** @var EscaperExtension $escaperExtension */
Expand Down
5 changes: 3 additions & 2 deletions tests/Integration/TwigEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class TwigEngineTest extends TestCase

private ObjectProphecy|TemplateChainResolverInterface|null $templateChainResolver = null;
private string $extension = 'html.twig';
private string $template = 'testTwigTemplate';
private string $template = 'testTwigTemplate.html.twig';
private string $templateDirPath;
private string $templatePath;

Expand All @@ -43,6 +43,7 @@ public function testExists(): void
{
$engine = $this->getEngine();
$this->assertTrue($engine->exists($this->template));
$this->assertFalse($engine->exists("foo.$this->extension"));
$this->assertFalse($engine->exists('foo'));
}

Expand Down Expand Up @@ -101,7 +102,7 @@ private function getEngine(): TwigEngine

private function getTemplateName(): string
{
return "{$this->template}.{$this->extension}";
return $this->template;
}

private function getTemplateDir(): string
Expand Down

0 comments on commit 7f71cbc

Please sign in to comment.