From bd89cc7b372826ab4fc98ac618605f0de70e47c7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Jul 2011 22:38:34 +0200 Subject: [PATCH] [FrameworkBundle] fixed Template parser to accept template with dots --- .../Templating/TemplateNameParser.php | 12 ++++++++---- .../Tests/CacheWarmer/TemplateFinderTest.php | 4 +++- .../Resources/views/this.is.not.a.template | 0 .../Fixtures/Resources/views/this.is.not.a.template | 0 .../Tests/Templating/TemplateNameParserTest.php | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/BaseBundle/Resources/views/this.is.not.a.template delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/this.is.not.a.template diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php index 9c6f48db2499..b886bbd20ff8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php @@ -62,11 +62,13 @@ public function parse($name) } $elements = explode('.', $parts[2]); - if (3 !== count($elements)) { + if (3 > count($elements)) { throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name)); } + $engine = array_pop($elements); + $format = array_pop($elements); - $template = new TemplateReference($parts[0], $parts[1], $elements[0], $elements[1], $elements[2]); + $template = new TemplateReference($parts[0], $parts[1], implode('.', $elements), $format, $engine); if ($template->get('bundle')) { try { @@ -91,11 +93,13 @@ public function parseFromFilename($file) $parts = explode('/', strtr($file, '\\', '/')); $elements = explode('.', array_pop($parts)); - if (3 !== count($elements)) { + if (3 > count($elements)) { return false; } + $engine = array_pop($elements); + $format = array_pop($elements); - return new TemplateReference('', implode('/', $parts), $elements[0], $elements[1], $elements[2]); + return new TemplateReference('', implode('/', $parts), implode('.', $elements), $format, $engine); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/TemplateFinderTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/TemplateFinderTest.php index f656408bf751..dc15a17da299 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/TemplateFinderTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/TemplateFinderTest.php @@ -47,9 +47,11 @@ function ($template) { return $template->getLogicalName(); }, $finder->findAllTemplates() ); - $this->assertEquals(3, count($templates), '->findAllTemplates() find all templates in the bundles and global folders'); + $this->assertEquals(5, count($templates), '->findAllTemplates() find all templates in the bundles and global folders'); $this->assertContains('BaseBundle::base.format.engine', $templates); + $this->assertContains('BaseBundle::this.is.a.template.format.engine', $templates); $this->assertContains('BaseBundle:controller:base.format.engine', $templates); + $this->assertContains('::this.is.a.template.format.engine', $templates); $this->assertContains('::resource.format.engine', $templates); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/BaseBundle/Resources/views/this.is.not.a.template b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/BaseBundle/Resources/views/this.is.not.a.template deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/this.is.not.a.template b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/this.is.not.a.template deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php index e0517ccc3029..4e86dc9a7c2c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php @@ -62,6 +62,7 @@ public function getLogicalNameToTemplateProvider() array('SensioCmsFooBundle:Post:index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')), array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')), array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')), + array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')), ); } @@ -81,7 +82,6 @@ public function getInvalidLogicalNameProvider() array('FooBundle:Post:index'), array('FooBundle:Post'), array('FooBundle:Post:foo:bar'), - array('FooBundle:Post:index.foo.bar.foobar'), ); }