Skip to content

Commit 1871da9

Browse files
committed
check if templating engine supports view
1 parent 5b5aefc commit 1871da9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Controller/ControllerTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, string
207207
*/
208208
protected function renderView(string $view, array $parameters = []): string
209209
{
210-
if ($this->container->has('templating')) {
210+
if ($this->container->has('templating') && $this->container->get('templating')->supports($view)) {
211211
@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);
212212

213213
return $this->container->get('templating')->render($view, $parameters);
@@ -227,7 +227,7 @@ protected function renderView(string $view, array $parameters = []): string
227227
*/
228228
protected function render(string $view, array $parameters = [], Response $response = null): Response
229229
{
230-
if ($this->container->has('templating')) {
230+
if ($this->container->has('templating') && $this->container->get('templating')->supports($view)) {
231231
@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);
232232

233233
$content = $this->container->get('templating')->render($view, $parameters);

Tests/Controller/ControllerTraitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ public function testRenderViewTemplating()
449449
{
450450
$templating = $this->createMock(EngineInterface::class);
451451
$templating->expects($this->once())->method('render')->willReturn('bar');
452+
$templating->expects($this->once())->method('supports')->willReturn(true);
452453

453454
$container = new Container();
454455
$container->set('templating', $templating);
@@ -466,6 +467,7 @@ public function testRenderTemplating()
466467
{
467468
$templating = $this->createMock(EngineInterface::class);
468469
$templating->expects($this->once())->method('render')->willReturn('bar');
470+
$templating->expects($this->once())->method('supports')->willReturn(true);
469471

470472
$container = new Container();
471473
$container->set('templating', $templating);

0 commit comments

Comments
 (0)