[FrameworkBundle][Template name] avoid error message for the shortcut notation.
This commit is contained in:
parent
f031154fa7
commit
055129c1c2
@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Templating;
|
namespace Symfony\Bundle\FrameworkBundle\Templating;
|
||||||
|
|
||||||
use Symfony\Component\Templating\TemplateNameParserInterface;
|
|
||||||
use Symfony\Component\Templating\TemplateReferenceInterface;
|
use Symfony\Component\Templating\TemplateReferenceInterface;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
use Symfony\Component\Templating\TemplateNameParser as BaseTemplateNameParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TemplateNameParser converts template names from the short notation
|
* TemplateNameParser converts template names from the short notation
|
||||||
@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class TemplateNameParser implements TemplateNameParserInterface
|
class TemplateNameParser extends BaseTemplateNameParser
|
||||||
{
|
{
|
||||||
protected $kernel;
|
protected $kernel;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
@ -57,7 +57,7 @@ class TemplateNameParser implements TemplateNameParserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
|
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]);
|
$template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]);
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||||
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
|
||||||
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
|
||||||
|
use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
|
||||||
|
|
||||||
class TemplateNameParserTest extends TestCase
|
class TemplateNameParserTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -63,25 +64,17 @@ class TemplateNameParserTest extends TestCase
|
|||||||
array(':Post:index.html.php', new TemplateReference('', '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('::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('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
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testParseInvalidName($name)
|
public function testParseValidNameWithNotFoundBundle()
|
||||||
{
|
{
|
||||||
$this->parser->parse($name);
|
$this->parser->parse('BarBundle:Post:index.html.php');
|
||||||
}
|
|
||||||
|
|
||||||
public function getInvalidLogicalNameProvider()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('BarBundle:Post:index.html.php'),
|
|
||||||
array('FooBundle:Post:index'),
|
|
||||||
array('FooBundle:Post'),
|
|
||||||
array('FooBundle:Post:foo:bar'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user