8000 bug #20440 [TwigBridge][TwigBundle][HttpKernel] prefer getSourceConte… · symfony/symfony@40dc73a · GitHub
[go: up one dir, main page]

Skip to content

Commit 40dc73a

Browse files
committed
bug #20440 [TwigBridge][TwigBundle][HttpKernel] prefer getSourceContext() over getSource() (xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- [TwigBridge][TwigBundle][HttpKernel] prefer getSourceContext() over getSource() | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20435 | License | MIT | Doc PR | n/a Commits ------- adbc529 prefer getSourceContext() over getSource()
2 parents 589d019 + adbc529 commit 40dc73a

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testTrans($template, $expected, array $variables = array())
3636
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
3737
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
3838

39-
echo $twig->compile($twig->parse($twig->tokenize(new \Twig_Source($twig->getLoader()->getSource('index'), 'index'))))."\n\n";
39+
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext('index'))))."\n\n";
4040
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
4141
}
4242

src/Symfony/Bridge/Twig/TwigEngine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public function exists($name)
7575

7676
$loader = $this->environment->getLoader();
7777

78-
if ($loader instanceof \Twig_ExistsLoaderInterface) {
78+
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
7979
return $loader->exists((string) $name);
8080
}
8181

8282
try {
8383
// cast possible TemplateReferenceInterface to string because the
8484
// EngineInterface supports them but Twig_LoaderInterface does not
85-
$loader->getSource((string) $name);
85+
$loader->getSourceContext((string) $name)->getCode();
8686
} catch (\Twig_Error_Loader $e) {
8787
return false;
8888
}

src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ protected function templateExists($template)
131131
$template = (string) $template;
132132

133133
$loader = $this->twig->getLoader();
134-
if ($loader instanceof \Twig_ExistsLoaderInterface) {
134+
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
135135
return $loader->exists($template);
136136
}
137137

138138
try {
139-
$loader->getSource($template);
139+
$loader->getSourceContext($template)->getCode();
140140

141141
return true;
142142
} catch (\Twig_Error_Loader $e) {

src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,16 @@ private function templateExists($template)
140140
}
141141

142142
$loader = $this->templating->getLoader();
143-
if ($loader instanceof \Twig_ExistsLoaderInterface) {
143+
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
144144
return $loader->exists($template);
145145
}
146146

147147
try {
148-
$loader->getSource($template);
148+
if (method_exists($loader, 'getSourceContext')) {
149+
$loader->getSourceContext($template);
150+
} else {
151+
$loader->getSource($template);
152+
}
149153

150154
return true;
151155
} catch (\Twig_Error_Loader $e) {

0 commit comments

Comments
 (0)
0