diff --git a/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php b/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php index 777ccb3..8fd0fd4 100644 --- a/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php +++ b/src/Resolver/TemplateChain/TemplateType/TemplateTypeFactory.php @@ -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; @@ -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) { @@ -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'."); - } - } } diff --git a/tests/Integration/Resolver/TemplateFileResolverTest.php b/tests/Integration/Resolver/TemplateFileResolverTest.php deleted file mode 100644 index 7233846..0000000 --- a/tests/Integration/Resolver/TemplateFileResolverTest.php +++ /dev/null @@ -1,43 +0,0 @@ -get(TemplateFileResolverInterface::class)->getFilename($templateName); - - $this->assertEquals($expectedFilename, $filename); - } - - public function templateNameFileDataProvider(): array - { - return [ - [ - 'template', - 'template.html.twig' - ], - [ - 'some/path/template_name.html.twig', - 'some/path/template_name.html.twig' - ], - ]; - } -} diff --git a/tests/Unit/Resolver/TemplateChain/TemplateType/TemplateTypeFactoryTest.php b/tests/Unit/Resolver/TemplateChain/TemplateType/TemplateTypeFactoryTest.php index cdbd82c..8269ba4 100644 --- a/tests/Unit/Resolver/TemplateChain/TemplateType/TemplateTypeFactoryTest.php +++ b/tests/Unit/Resolver/TemplateChain/TemplateType/TemplateTypeFactoryTest.php @@ -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; @@ -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); } }