8000 fix compatibility with Twig 3.10 · symfony/symfony@4fdc286 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4fdc286

Browse files
committed
fix compatibility with Twig 3.10
1 parent c5e56bb commit 4fdc286

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Bundle/WebProfilerBundle/Tests/Twig/WebProfilerExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension;
1616
use Symfony\Component\VarDumper\Cloner\VarCloner;
1717
use Twig\Environment;
18+
use Twig\Loader\ArrayLoader;
1819

1920
class WebProfilerExtensionTest extends TestCase
2021
{
@@ -23,7 +24,7 @@ class WebProfilerExtensionTest extends TestCase
2324
*/
2425
public function testDumpHeaderIsDisplayed(string $message, array $context, bool $dump1HasHeader, bool $dump2HasHeader)
2526
{
26-
$twigEnvironment = $this->mockTwigEnvironment();
27+
$twigEnvironment = new Environment(new ArrayLoader());
2728
$varCloner = new VarCloner();
2829

2930
$webProfilerExtension = new WebProfilerExtension();

src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Twig\Extension\EscaperExtension;
1818
use Twig\Extension\ProfilerExtension;
1919
use Twig\Profiler\Profile;
20+
use Twig\Runtime\EscaperRuntime;
2021
use Twig\TwigFunction;
2122

2223
/**
@@ -114,10 +115,15 @@ public function getName()
114115

115116
private static function escape(Environment $env, string $s): string
116117
{
118+
// Twig 3.9
117119
if (method_exists(EscaperExtension::class, 'escape')) {
118120
return EscaperExtension::escape($env, $s);
119121
}
120122

123+
if (class_exists(EscaperRuntime::class) && null !== $escaperRuntime = $env->getRuntime(EscaperRuntime::class)) {
124+
return $escaperRuntime->escape($s);
125+
}
126+
121127
// to be removed when support for Twig 3 is dropped
122128
return twig_escape_filter($env, $s);
123129
}

0 commit comments

Comments
 (0)
0