From 357f1fabde48312c1874ea028fc948516ce8afa2 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 --- .../TemplateChain/TemplateType/TemplateTypeFactory.php | 7 ------- src/TwigEngine.php | 10 +--------- tests/Integration/TwigEngineTest.php | 5 +++-- 3 files changed, 4 insertions(+), 18 deletions(-) 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..d37b66c 100644 --- a/src/TwigEngine.php +++ b/src/TwigEngine.php @@ -67,7 +67,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 +95,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