From 7f71cbc512324639fe99fad90d133d658d425493 Mon Sep 17 00:00:00 2001 From: Jelle Dehn Date: Tue, 21 Nov 2023 14:01:12 +0100 Subject: [PATCH] OXDEV-6895 change template filename resolver --- services.yaml | 1 - .../TemplateType/TemplateTypeFactory.php | 7 ------- src/TwigEngine.php | 11 +---------- tests/Integration/TwigEngineTest.php | 5 +++-- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/services.yaml b/services.yaml index ace5a96..2b7a294 100644 --- a/services.yaml +++ b/services.yaml @@ -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 diff --git a/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php b/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php index 777ccb3..367cfc6 100644 --- a/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php +++ b/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php @@ -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)) { @@ -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)) { diff --git a/src/TwigEngine.php b/src/TwigEngine.php index fce831b..5c09327 100644 --- a/src/TwigEngine.php +++ b/src/TwigEngine.php @@ -20,7 +20,6 @@ class TwigEngine implements TemplateEngineInterface { public function __construct( private Environment $engine, - private string $fileExtension, private TemplateChainResolverInterface $templateChainResolver, iterable $twigExtensions = [], iterable $twigEscaper = [] @@ -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); } /** @@ -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 */ diff --git a/tests/Integration/TwigEngineTest.php b/tests/Integration/TwigEngineTest.php index d396c69..da7f7aa 100644 --- a/tests/Integration/TwigEngineTest.php +++ b/tests/Integration/TwigEngineTest.php @@ -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; @@ -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')); } @@ -101,7 +102,7 @@ private function getEngine(): TwigEngine private function getTemplateName(): string { - return "{$this->template}.{$this->extension}"; + return $this->template; } private function getTemplateDir(): string