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 357f1fa
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
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
10 changes: 1 addition & 9 deletions src/TwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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 */
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 357f1fa

Please sign in to comment.