mirror of
https://github.com/twigphp/Twig.git
synced 2026-11-04 18:14:55 +00:00
Fetch the escaper runtime once in the constructor of templates that escape
This commit is contained in:
+12
-1
@@ -74,6 +74,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
|
||||
'index' => null,
|
||||
'embedded_templates' => $embeddedTemplates,
|
||||
'strategy' => false,
|
||||
'escaper' => false,
|
||||
], 1);
|
||||
|
||||
// populate the template name of all node children
|
||||
@@ -201,8 +202,14 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
|
||||
->write("/**\n")
|
||||
->write(" * @var array<string, MacroNamespace>\n")
|
||||
->write(" */\n")
|
||||
->write("private array \$macros = [];\n\n")
|
||||
->write("private array \$macros = [];\n")
|
||||
;
|
||||
|
||||
if ($this->getAttribute('escaper')) {
|
||||
$compiler->write("private \\Twig\\Runtime\\EscaperRuntime \$escaper;\n");
|
||||
}
|
||||
|
||||
$compiler->raw("\n");
|
||||
}
|
||||
|
||||
protected function compileConstructor(Compiler $compiler): void
|
||||
@@ -215,6 +222,10 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
|
||||
->write("\$this->source = \$this->getSourceContext();\n\n")
|
||||
;
|
||||
|
||||
if ($this->getAttribute('escaper')) {
|
||||
$compiler->write("\$this->escaper = \$env->getRuntime('Twig\\Runtime\\EscaperRuntime');\n\n");
|
||||
}
|
||||
|
||||
// parent
|
||||
if (!$this->hasNode('parent')) {
|
||||
$compiler->write("\$this->parent = false;\n\n");
|
||||
|
||||
Reference in New Issue
Block a user