Redesign macro calls and argument handling#4851
Conversation
| // both "import" and "from" now route through Template::callMacro(), the two paths | ||
| // only differ in this parse-time symbol plumbing. In 4.0, unify "from" onto the | ||
| // "template" import symbol and remove the dedicated "function"-symbol branch in | ||
| // FunctionExpressionParser. |
There was a problem hiding this comment.
How can this actually happen ? The source being parsed looks like a function expression in the case of a usage based on from.
|
📋 PR Summary This PR redesigns Twig's macro call and argument handling: macro invocation is unified through new Changes
|
There was a problem hiding this comment.
📋 Upsun Dispatch Review: full · 40 files reviewed · no issues found
Review details
Commit: Commit dd55a6e
Model: claude-opus-4-8
Panel: correctness · robustness · design
|
@stof I think I've taken all your comments into account. |
| if (null !== $declaration = $this->findDeclaredMacroName($name, $context)) { | ||
| [$declaredName, $templateName] = $declaration; | ||
| if ($declaredName !== $name) { | ||
| trigger_deprecation('twig/twig', '3.28', 'Testing whether the macro "%s" (defined in template "%s") is defined as "%s" is deprecated; macro names will be case-sensitive in Twig 4.0 and this test will return false.', $declaredName, $templateName, $name); |
There was a problem hiding this comment.
🟡 Warning — Wrong version attribution misleads users about when a deprecation/feature landed.
The version was bumped to 3.29.0 in this PR (Environment::VERSION = '3.29.0-DEV', CHANGELOG opens with # 3.29.0), yet the new deprecation strings and doc annotations still reference 3.28. trigger_deprecation('twig/twig', '3.28', ...) here — and the identical calls at lines 578 and 612, those in TwigMacro.php (168, 177, 182), plus the .. deprecated:: 3.28/.. versionadded:: 3.28 blocks and @final since Twig 3.28 on MacroNode — will attribute these deprecations/features to 3.28, but since 3.28.0 is already released they actually ship in 3.29.0. Update the version strings to 3.29.
This is my attempt to make macros "better". It uses modern PHP features that didn't exist when I designed macros a long time ago.
The first objective is to close the gap between their behavior and the behavior of Twig callables: functions, filters, and tests.
Here are some important changes:
null.varargsvariable....name.macro_*methods.The refactor introduces
TwigMacroandMacroArgumentto represent template-defined macros with an explicit signature, similar to the existing Twig callable model.