Skip to content

[FrameworkBundle][Template name] avoid error message for the shortcut n... #12894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Symfony\Bundle\FrameworkBundle\Templating;

use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Templating\TemplateNameParser as BaseTemplateNameParser;

/**
* TemplateNameParser converts template names from the short notation
Expand All @@ -22,7 +22,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class TemplateNameParser implements TemplateNameParserInterface
class TemplateNameParser extends BaseTemplateNameParser
{
protected $kernel;
protected $cache;
Expand Down Expand Up @@ -57,7 +57,7 @@ public function parse($name)
}

if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
return parent::parse($name);
}

$template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;

class TemplateNameParserTest extends TestCase
{
Expand Down Expand Up @@ -63,25 +64,17 @@ public function getLogicalNameToTemplateProvider()
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')),
array('/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
array('name.twig', new BaseTemplateReference('name.twig', 'twig')),
array('name', new BaseTemplateReference('name')),
);
}

/**
* @dataProvider getInvalidLogicalNameProvider
* @expectedException \InvalidArgumentException
*/
public function testParseInvalidName($name)
public function testParseValidNameWithNotFoundBundle()
{
$this->parser->parse($name);
}

public function getInvalidLogicalNameProvider()
{
return array(
array('BarBundle:Post:index.html.php'),
array('FooBundle:Post:index'),
array('FooBundle:Post'),
array('FooBundle:Post:foo:bar'),
);
$this->parser->parse('BarBundle:Post:index.html.php');
}
}