Expose the escaping strategy a template was compiled with

This commit is contained in:
Fabien Potencier
2026-09-19 09:12:49 +01:00
parent ea3258396c
commit 26812ebc0d
8 changed files with 201 additions and 0 deletions
+23
View File
@@ -73,6 +73,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
parent::__construct($nodes, [
'index' => null,
'embedded_templates' => $embeddedTemplates,
'strategy' => false,
], 1);
// populate the template name of all node children
@@ -121,6 +122,8 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
$this->compileIsTraitable($compiler);
$this->compileGetDefaultEscapeStrategy($compiler);
$this->compileDebugInfo($compiler);
$this->compileGetSourceContext($compiler);
@@ -462,6 +465,26 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
;
}
protected function compileGetDefaultEscapeStrategy(Compiler $compiler): void
{
if (false === $strategy = $this->getAttribute('strategy')) {
return;
}
$compiler
->write("/**\n")
->write(" * @codeCoverageIgnore\n")
->write(" */\n")
->write("public function getDefaultEscapeStrategy(): string|false\n", "{\n")
->indent()
->write('return ')
->repr($strategy)
->raw(";\n")
->outdent()
->write("}\n\n")
;
}
protected function compileDebugInfo(Compiler $compiler): void
{
$compiler