From 99cb909ad9f8703c91e7554a0327ec5e3dd0f45b Mon Sep 17 00:00:00 2001 From: sneakyvv Date: Thu, 16 Jan 2025 14:21:39 +0100 Subject: [PATCH] Remove obsolete TemplateNameParser It no longer parses (and should not have been stripping namespaces as it did before) --- src/TwigComponent/src/Twig/ComponentNode.php | 2 +- .../src/Twig/ComponentTokenParser.php | 2 +- .../src/Twig/TemplateNameParser.php | 36 -------------- .../Unit/Twig/TemplateNameParserTest.php | 47 ------------------- 4 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 src/TwigComponent/src/Twig/TemplateNameParser.php delete mode 100644 src/TwigComponent/tests/Unit/Twig/TemplateNameParserTest.php diff --git a/src/TwigComponent/src/Twig/ComponentNode.php b/src/TwigComponent/src/Twig/ComponentNode.php index 439175c5bfa..df735079570 100644 --- a/src/TwigComponent/src/Twig/ComponentNode.php +++ b/src/TwigComponent/src/Twig/ComponentNode.php @@ -112,7 +112,7 @@ public function compile(Compiler $compiler): void ->raw('), ') ->raw($this->getAttribute('only') ? '[]' : '$context') ->raw(', ') - ->string(TemplateNameParser::parse($this->getAttribute('embedded_template'))) + ->string($this->getAttribute('embedded_template')) ->raw(', ') ->raw($this->getAttribute('embedded_index')) ->raw(");\n"); diff --git a/src/TwigComponent/src/Twig/ComponentTokenParser.php b/src/TwigComponent/src/Twig/ComponentTokenParser.php index 3f94c09d627..317564681ea 100644 --- a/src/TwigComponent/src/Twig/ComponentTokenParser.php +++ b/src/TwigComponent/src/Twig/ComponentTokenParser.php @@ -63,7 +63,7 @@ public function parse(Token $token): Node $this->parser->embedTemplate($module); // override the embedded index with a deterministic value, so it can be loaded in a controlled manner - $module->setAttribute('index', $this->generateEmbeddedTemplateIndex(TemplateNameParser::parse($stream->getSourceContext()->getName()), $token->getLine())); + $module->setAttribute('index', $this->generateEmbeddedTemplateIndex($stream->getSourceContext()->getName(), $token->getLine())); $stream->expect(Token::BLOCK_END_TYPE); diff --git a/src/TwigComponent/src/Twig/TemplateNameParser.php b/src/TwigComponent/src/Twig/TemplateNameParser.php deleted file mode 100644 index 2c9d5918f79..00000000000 --- a/src/TwigComponent/src/Twig/TemplateNameParser.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\UX\TwigComponent\Twig; - -/** - * @internal - */ -final class TemplateNameParser -{ - /** - * Copied from Twig\Loader\FilesystemLoader, and adjusted to needs for this class. - * - * @see \Twig\Loader\FilesystemLoader::parseName - */ - public static function parse(string $name): string - { - if (str_starts_with($name, '@')) { - if (!str_contains($name, '/')) { - throw new \LogicException(\sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); - } - - return $name; - } - - return $name; - } -} diff --git a/src/TwigComponent/tests/Unit/Twig/TemplateNameParserTest.php b/src/TwigComponent/tests/Unit/Twig/TemplateNameParserTest.php deleted file mode 100644 index 890a8caa85c..00000000000 --- a/src/TwigComponent/tests/Unit/Twig/TemplateNameParserTest.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\UX\TwigComponent\Tests\Unit\Twig; - -use PHPUnit\Framework\TestCase; -use Symfony\UX\TwigComponent\Twig\TemplateNameParser; - -/** - * @author Simon André - */ -class TemplateNameParserTest extends TestCase -{ - /** - * @dataProvider provideParse - */ - public function testParse(string $name, string $parsedName): void - { - $this->assertSame($parsedName, TemplateNameParser::parse($name)); - } - - public function testParseThrowsExceptionWhenInvalidName(): void - { - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Malformed namespaced template name "@foo" (expecting "@namespace/template_name").'); - TemplateNameParser::parse('@foo'); - } - - /** - * @return iterable - */ - public static function provideParse(): iterable - { - yield ['foo', 'foo']; - yield ['foo/bar', 'foo/bar']; - yield ['@Admin/foo', '@Admin/foo']; - yield ['Admin/foo', 'Admin/foo']; - } -}