Redesign macro calls and argument handling

This commit is contained in:
Fabien Potencier
2026-07-27 12:50:45 +02:00
parent e315d6d396
commit d7f8b4eb1c
60 changed files with 1631 additions and 299 deletions
+9 -2
View File
@@ -31,13 +31,19 @@ use Twig\Source;
final class ModuleNode extends Node implements CoercesChildrenToStringInterface
{
/**
* @param BodyNode $body
* @param BodyNode $body
* @param MacrosNode $macros
*/
public function __construct(Node $body, ?AbstractExpression $parent, Node $blocks, Node $macros, Node $traits, $embeddedTemplates, Source $source)
{
if (!$body instanceof BodyNode) {
trigger_deprecation('twig/twig', '3.12', \sprintf('Not passing a "%s" instance as the "body" argument of the "%s" constructor is deprecated.', BodyNode::class, static::class));
}
if (!$macros instanceof MacrosNode) {
trigger_deprecation('twig/twig', '3.29', \sprintf('Not passing a "%s" instance as the "macros" argument of the "%s" constructor is deprecated.', MacrosNode::class, static::class));
$macros = new MacrosNode(iterator_to_array($macros));
}
if (!$embeddedTemplates instanceof Node) {
trigger_deprecation('twig/twig', '3.21', \sprintf('Not passing a "%s" instance as the "embedded_templates" argument of the "%s" constructor is deprecated.', Node::class, static::class));
@@ -167,6 +173,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
->write("use Twig\Error\RuntimeError;\n")
->write("use Twig\Extension\CoreExtension;\n")
->write("use Twig\Extension\SandboxExtension;\n")
->write("use Twig\MacroNamespace;\n")
->write("use Twig\Markup;\n")
->write("use Twig\Sandbox\SecurityError;\n")
->write("use Twig\Sandbox\SecurityNotAllowedTagError;\n")
@@ -188,7 +195,7 @@ final class ModuleNode extends Node implements CoercesChildrenToStringInterface
->indent()
->write("private Source \$source;\n")
->write("/**\n")
->write(" * @var array<string, Template>\n")
->write(" * @var array<string, MacroNamespace>\n")
->write(" */\n")
->write("private array \$macros = [];\n\n")
;