Skip to content

Commit 60ac845

Browse files
committed
fix compatibility with Twig 3.10
1 parent c5e56bb commit 60ac845

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-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: 7 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,6 +115,12 @@ public function getName()
114115

115116
private static function escape(Environment $env, string $s): string
116117
{
118+
// Twig 3.10 and above
119+
if (class_exists(EscaperRuntime::class) && null !== $escaperRuntime = $env->getRuntime(EscaperRuntime::class)) {
120+
return $escaperRuntime->escape($s);
121+
}
122+
123+
// Twig 3.9
117124
if (method_exists(EscaperExtension::class, 'escape')) {
118125
return EscaperExtension::escape($env, $s);
119126
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy