Skip to content

Commit bd89cc7

Browse files
committed
[FrameworkBundle] fixed Template parser to accept template with dots
1 parent e293fb7 commit bd89cc7

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ public function parse($name)
6262
}
6363

6464
$elements = explode('.', $parts[2]);
65-
if (3 !== count($elements)) {
65+
if (3 > count($elements)) {
6666
throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
6767
}
68+
$engine = array_pop($elements);
69+
$format = array_pop($elements);
6870

69-
$template = new TemplateReference($parts[0], $parts[1], $elements[0], $elements[1], $elements[2]);
71+
$template = new TemplateReference($parts[0], $parts[1], implode('.', $elements), $format, $engine);
7072

7173
if ($template->get('bundle')) {
7274
try {
@@ -91,11 +93,13 @@ public function parseFromFilename($file)
9193
$parts = explode('/', strtr($file, '\\', '/'));
9294

9395
$elements = explode('.', array_pop($parts));
94-
if (3 !== count($elements)) {
96+
if (3 > count($elements)) {
9597
return false;
9698
}
99+
$engine = array_pop($elements);
100+
$format = array_pop($elements);
97101

98-
return new TemplateReference('', implode('/', $parts), $elements[0], $elements[1], $elements[2]);
102+
return new TemplateReference('', implode('/', $parts), implode('.', $elements), $format, $engine);
99103
}
100104

101105
}

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/TemplateFinderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ function ($template) { return $template->getLogicalName(); },
4747
$finder->findAllTemplates()
4848
);
4949

50-
$this->assertEquals(3, count($templates), '->findAllTemplates() find all templates in the bundles and global folders');
50+
$this->assertEquals(5, count($templates), '->findAllTemplates() find all templates in the bundles and global folders');
5151
$this->assertContains('BaseBundle::base.format.engine', $templates);
52+
$this->assertContains('BaseBundle::this.is.a.template.format.engine', $templates);
5253
$this->assertContains('BaseBundle:controller:base.format.engine', $templates);
54+
$this->assertContains('::this.is.a.template.format.engine', $templates);
5355
$this->assertContains('::resource.format.engine', $templates);
5456
}
5557

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/BaseBundle/Resources/views/this.is.not.a.template

Whitespace-only changes.

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/this.is.not.a.template

Whitespace-only changes.

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function getLogicalNameToTemplateProvider()
6262
array('SensioCmsFooBundle:Post:index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')),
6363
array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
6464
array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
65+
array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
6566
);
6667
}
6768

@@ -81,7 +82,6 @@ public function getInvalidLogicalNameProvider()
8182
array('FooBundle:Post:index'),
8283
array('FooBundle:Post'),
8384
array('FooBundle:Post:foo:bar'),
84-
array('FooBundle:Post:index.foo.bar.foobar'),
8585
);
8686
}
8787

0 commit comments

Comments
 (0)