14
14
use Symfony \Component \VarDumper \Cloner \Data ;
15
15
use Symfony \Component \VarDumper \Dumper \HtmlDumper ;
16
16
use Twig \Environment ;
17
+ use Twig \Extension \EscaperExtension ;
17
18
use Twig \Extension \ProfilerExtension ;
18
19
use Twig \Profiler \Profile ;
19
20
use Twig \TwigFunction ;
@@ -60,9 +61,6 @@ public function leave(Profile $profile): void
60
61
}
61
62
}
62
63
63
- /**
64
- * {@inheritdoc}
65
- */
66
64
public function getFunctions (): array
67
65
{
68
66
return [
@@ -87,12 +85,12 @@ public function dumpData(Environment $env, Data $data, int $maxDepth = 0)
87
85
88
86
public function dumpLog (Environment $ env , string $ message , Data $ context = null )
89
87
{
90
- $ message = twig_escape_filter ($ env , $ message );
88
+ $ message = self :: escape ($ env , $ message );
91
89
$ message = preg_replace ('/"(.*?)"/ ' , '"<b>$1</b>" ' , $ message );
92
90
93
91
$ replacements = [];
94
92
foreach ($ context ?? [] as $ k => $ v ) {
95
- $ k = '{ ' .twig_escape_filter ($ env , $ k ).'} ' ;
93
+ $ k = '{ ' .self :: escape ($ env , $ k ).'} ' ;
96
94
if (str_contains ($ message , $ k )) {
97
95
$ replacements [$ k ] = $ v ;
98
96
}
@@ -109,11 +107,18 @@ public function dumpLog(Environment $env, string $message, Data $context = null)
109
107
return '<span class="dump-inline"> ' .strtr ($ message , $ replacements ).'</span> ' ;
110
108
}
111
109
112
- /**
113
- * {@inheritdoc}
114
- */
115
110
public function getName ()
116
111
{
117
112
return 'profiler ' ;
118
113
}
114
+
115
+ private static function escape (Environment $ env , string $ s ): string
116
+ {
117
+ if (method_exists (EscaperExtension::class, 'escape ' )) {
118
+ return EscaperExtension::escape ($ env , $ s );
119
+ }
120
+
121
+ // to be removed when support for Twig 3 is dropped
122
+ return twig_escape_filter ($ env , $ s );
123
+ }
119
124
}
0 commit comments