Merge pull request #8190 from emodric/patch-3

[ThemeBundle] Fix support for custom Twig namespaces
This commit is contained in:
Łukasz Chruściel 2017-06-23 08:56:28 +02:00 committed by GitHub
commit c9bdf0d05d
2 changed files with 10 additions and 5 deletions

View file

@ -76,7 +76,7 @@ final class TemplateNameParser implements TemplateNameParserInterface
try {
$this->kernel->getBundle($template->get('bundle'));
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
return $this->decoratedParser->parse($name);
}
}

View file

@ -63,11 +63,16 @@ final class TemplateNameParserSpec extends ObjectBehavior
$this->parse('@Acme/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Nested/Directory', 'app', 'html', 'twig'));
}
function it_throws_an_exception_if_namespaced_path_references_not_existing_bundle(KernelInterface $kernel)
{
$kernel->getBundle('AcmeBundle')->willThrow(\Exception::class);
function it_delegates_custom_namespace_to_decorated_parser(
KernelInterface $kernel,
TemplateNameParserInterface $decoratedParser,
TemplateReferenceInterface $templateReference
) {
$kernel->getBundle('myBundle')->willThrow(\Exception::class);
$this->shouldThrow(\InvalidArgumentException::class)->during('parse', ['@Acme/app.html.twig']);
$decoratedParser->parse('@my/custom/namespace.html.twig')->willReturn($templateReference);
$this->parse('@my/custom/namespace.html.twig')->shouldReturn($templateReference);
}
function it_generates_template_references_from_root_namespaced_paths()