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 21, 2023
1 parent ca86ed3 commit 585b930
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 68 deletions.
19 changes: 0 additions & 19 deletions src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OxidEsales\Twig\Resolver\TemplateChain\TemplateType;

use OxidEsales\EshopCommunity\Internal\Framework\Templating\Resolver\TemplateFileResolverInterface;
use OxidEsales\Twig\Resolver\TemplateChain\TemplateType\DataObject\ModuleExtensionTemplateType;
use OxidEsales\Twig\Resolver\TemplateChain\TemplateType\DataObject\ModuleTemplateType;
use OxidEsales\Twig\Resolver\TemplateChain\TemplateType\DataObject\ShopExtensionTemplateType;
Expand All @@ -18,25 +17,19 @@
use Twig\Loader\FilesystemLoader;

use function preg_match;
use function str_ends_with;

class TemplateTypeFactory implements TemplateTypeFactoryInterface
{
private const TWIG_FILE_EXTENSION = '.twig';
private const MODULE_EXTENSION_TEMPLATE_TYPE_PATTERN = '%^@*([^\s/]+)/extensions/modules/([^\s/]+)/(.+)$%i';
private const SHOP_EXTENSION_TEMPLATE_TYPE_PATTERN = '%^@([^\s/]+)/extensions/themes/([^\s/]+)/(.+)$%i';
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)) {
[, $namespace, $extendsNamespace, $name,] = $this->parseAsModuleExtensionFullyQualifiedName($templateName);
if ($namespace && $extendsNamespace && $name) {
Expand Down Expand Up @@ -93,16 +86,4 @@ 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)) {
throw new NonTemplateFilenameException("Can not process non-template file '$templateName'.");
}
}
}
43 changes: 0 additions & 43 deletions tests/Integration/Resolver/TemplateFileResolverTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OxidEsales\Twig\Tests\Unit\Resolver\TemplateChain\TemplateType;

use OxidEsales\EshopCommunity\Internal\Framework\Templating\Resolver\TemplateFileResolver;
use OxidEsales\Twig\Resolver\TemplateChain\TemplateType\DataObject\ModuleExtensionTemplateType;
use OxidEsales\Twig\Resolver\TemplateChain\TemplateType\DataObject\ModuleTemplateType;
use OxidEsales\Twig\Resolver\TemplateChain\TemplateType\DataObject\ShopExtensionTemplateType;
Expand Down Expand Up @@ -114,10 +113,6 @@ public function testCreateFromTemplateNameWithModuleExtension(): void

private function getTemplateType(string $templatePath): TemplateTypeInterface
{
$templateTypeFactory = new TemplateTypeFactory(
new TemplateFileResolver($this->extension)
);

return $templateTypeFactory->createFromTemplateName($templatePath);
return (new TemplateTypeFactory())->createFromTemplateName($templatePath);
}
}

0 comments on commit 585b930

Please sign in to comment.