Skip to content

Commit c9fb6ed

Browse files
committed
bug #12197 [TwigBundle] do not pass a template reference to twig (Tobion)
This PR was merged into the 2.3 branch. Discussion ---------- [TwigBundle] do not pass a template reference to twig | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - twig does not know about template references and only expects a string. this commit also fixes that name parsing and locating was called twice for nonexistent templates. Commits ------- 7fe33e3 [TwigBundle] do not pass a template reference to twig
2 parents c503822 + 4c2f2d2 commit c9fb6ed

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

Controller/ExceptionController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpFoundation\Response;
19+
use Symfony\Component\Templating\TemplateReferenceInterface;
1920

2021
/**
2122
* ExceptionController.
@@ -51,7 +52,7 @@ public function showAction(Request $request, FlattenException $exception, DebugL
5152
$code = $exception->getStatusCode();
5253

5354
return new Response($this->twig->render(
54-
$this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug),
55+
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug),
5556
array(
5657
'status_code' => $code,
5758
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
@@ -88,7 +89,7 @@ protected function getAndCleanOutputBuffering($startObLevel)
8889
* @param int $code An HTTP response status code
8990
* @param bool $debug
9091
*
91-
* @return TemplateReference
92+
* @return TemplateReferenceInterface
9293
*/
9394
protected function findTemplate(Request $request, $format, $code, $debug)
9495
{

Loader/FilesystemLoader.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,12 @@ public function __construct(FileLocatorInterface $locator, TemplateNameParserInt
4343

4444
/**
4545
* {@inheritdoc}
46+
*
47+
* The name parameter might also be a TemplateReferenceInterface.
4648
*/
47-
public function exists($template)
49+
public function exists($name)
4850
{
49-
if (parent::exists($template)) {
50-
return true;
51-
}
52-
53-
// same logic as findTemplate below for the fallback
54-
try {
55-
$this->cache[(string) $template] = $this->locator->locate($this->parser->parse($template));
56-
} catch (\Exception $e) {
57-
return false;
58-
}
59-
60-
return true;
51+
return parent::exists((string) $name);
6152
}
6253

6354
/**
@@ -84,18 +75,14 @@ protected function findTemplate($template)
8475
$file = null;
8576
$previous = null;
8677
try {
87-
$file = parent::findTemplate($template);
78+
$file = parent::findTemplate($logicalName);
8879
} catch (\Twig_Error_Loader $e) {
8980
$previous = $e;
9081

9182
// for BC
9283
try {
9384
$template = $this->parser->parse($template);
94-
try {
95-
$file = $this->locator->locate($template);
96-
} catch (\InvalidArgumentException $e) {
97-
$previous = $e;
98-
}
85+
$file = $this->locator->locate($template);
9986
} catch (\Exception $e) {
10087
$previous = $e;
10188
}

0 commit comments

Comments
 (0)