From 0f9434c1896dceb41274fce0f8e3993732b01877 Mon Sep 17 00:00:00 2001 From: fritzmg Date: Fri, 5 Mar 2021 11:13:54 +0000 Subject: [PATCH] check if templating engine supports view --- .../Bundle/FrameworkBundle/Controller/ControllerTrait.php | 4 ++-- .../FrameworkBundle/Tests/Controller/ControllerTraitTest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php index a5d00cdcec5b9..99516b5c3fac6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php @@ -207,7 +207,7 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, string */ protected function renderView(string $view, array $parameters = []): string { - if ($this->container->has('templating')) { + if ($this->container->has('templating') && $this->container->get('templating')->supports($view)) { @trigger_error('Using the "templating" service is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', \E_USER_DEPRECATED); return $this->container->get('templating')->render($view, $parameters); @@ -227,7 +227,7 @@ protected function renderView(string $view, array $parameters = []): string */ protected function render(string $view, array $parameters = [], Response $response = null): Response { - if ($this->container->has('templating')) { + if ($this->container->has('templating') && $this->container->get('templating')->supports($view)) { @trigger_error('Using the "templating" service is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', \E_USER_DEPRECATED); $content = $this->container->get('templating')->render($view, $parameters); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php index a5392b0cc0e82..00007aee3af4a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php @@ -449,6 +449,7 @@ public function testRenderViewTemplating() { $templating = $this->createMock(EngineInterface::class); $templating->expects($this->once())->method('render')->willReturn('bar'); + $templating->expects($this->once())->method('supports')->willReturn(true); $container = new Container(); $container->set('templating', $templating); @@ -466,6 +467,7 @@ public function testRenderTemplating() { $templating = $this->createMock(EngineInterface::class); $templating->expects($this->once())->method('render')->willReturn('bar'); + $templating->expects($this->once())->method('supports')->willReturn(true); $container = new Container(); $container->set('templating', $templating);