Skip to content

Commit

Permalink
[FrameworkBundle] fixed Template parser to accept template with dots
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jul 4, 2011
1 parent e293fb7 commit bd89cc7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Expand Up @@ -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 {
Expand All @@ -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);
}

}
Expand Up @@ -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);
}

Expand Down
Empty file.
Empty file.
Expand Up @@ -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')),
);
}

Expand All @@ -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'),
);
}

Expand Down

0 comments on commit bd89cc7

Please sign in to comment.