Commit Graph

897 Commits

Author SHA1 Message Date
Fabien Potencier 1d8243b73e Cleanup PHPUnit compatibility 2026-09-05 11:18:32 +02:00
Fabien Potencier 551752a92b Remove redundant data provider compatibility test 2026-08-29 09:45:29 +02:00
Fabien Potencier f640320202 Merge branch '3.x' into 4.x
* 3.x: (26 commits)
  Remove the documentation comments compilation overhead
  Clarify source function trust requirements
  Throw on PCRE errors in the matches operator
  Document that reusing a non-rewindable iterator after destructuring is unsupported
  Release destructuring temporaries after assignment
  Deprecate prefixed macro definedness checks
  Fix duplicate macro deprecation wording
  Throw when list formatting fails
  Document that sequence destructuring consumes one value per pattern slot
  Fix the html_attr documentation about iterables in data attributes
  Warn about untrusted input with the default Tempest markdown converter
  Document that overriding MacroNode::compile() is not supported anymore
  Merge overlapping CHANGELOG entries for the destructuring fatal error fix
  Document that include_only keeps global variables available
  Remove lazy macro import resolution
  Honor date formatter prototype calendars
  Fix Stringable keys for ArrayAccess implementations
  Fix repeated object destructuring evaluation
  Restore void return type compatibility for extension points
  Reject destructuring patterns containing no variables
  ...

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	doc/filters/format_datetime.rst
#	extra/twig-extra-bundle/DependencyInjection/Compiler/MissingExtensionSuggestorPass.php
#	extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php
#	extra/twig-extra-bundle/TwigExtraBundle.php
#	src/MacroNamespace.php
#	src/Node/MacrosNode.php
#	src/Parser.php
#	src/Test/IntegrationTestCase.php
#	src/Test/NodeTestCase.php
#	tests/CallMacroTest.php
#	tests/ExpressionParserTest.php
#	tests/Fixtures/macros/duplicate_definition.legacy.test
#	tests/Node/MacrosTest.php
#	tests/ParserTest.php
2026-08-29 00:25:20 +02:00
Fabien Potencier c32656815b minor #4908 Remove the documentation comments compilation overhead (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Remove the documentation comments compilation overhead

Documentation comments are now attached to semantic nodes during parsing, removing the dedicated AST traversal. Token parsers returning placeholder nodes can select the semantic documentation target.

Commits
-------

60eed4ccd5 Remove the documentation comments compilation overhead
2026-08-29 00:19:33 +02:00
Fabien Potencier 60eed4ccd5 Remove the documentation comments compilation overhead 2026-08-29 00:19:29 +02:00
Fabien Potencier dd0bd0ffbc minor #4904 Release destructuring temporaries after assignment (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Release destructuring temporaries after assignment

The compiled destructuring code kept the right-hand side alive in a hidden local until the end of rendering, wasting memory on large arrays and iterators. The temporary is now cleared as part of the compiled expression.

The way it works:

For this Twig expression:

```twig
{% do {name, email: address} = user %}
```

The previous generated expression was conceptually:

```php
[$context["name"], $context["address"]] = [
    getAttribute($_v0 = $context["user"], "name"),
    getAttribute($_v0, "email"),
];
```

The branch now generates:

```php
[
    [$context["name"], $context["address"]] = [
        getAttribute($_v0 = $context["user"], "name"),
        getAttribute($_v0, "email"),
    ],
    $_v0 = null,
][0]
```

The important wrapper is:

```php
[$originalExpression, $_v0 = null][0]
```

PHP evaluates array elements from left to right:

1. The original destructuring assignment runs.
2. The temporary variable is set to `null`, releasing its reference.
3. `[0]` returns the result of the original expression.

This preserves Twig’s rule that a destructuring expression returns its right-hand value.

Commits
-------

c459ef0bdd Release destructuring temporaries after assignment
2026-08-29 00:15:46 +02:00
Fabien Potencier e5347301d7 Throw on PCRE errors in the matches operator 2026-08-28 08:41:42 +02:00
Fabien Potencier 0c9d0c77c0 bug #4906 Deprecate prefixed macro definedness checks (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate prefixed macro definedness checks

Testing a macro through a legacy `macro_`-prefixed name would have silently returned `false` in Twig 4.0 without ever warning; `has()` now triggers the same deprecation as `call()`.

Commits
-------

977aef7172 Deprecate prefixed macro definedness checks
2026-08-27 17:57:48 +02:00
Fabien Potencier c459ef0bdd Release destructuring temporaries after assignment 2026-08-27 13:32:19 +02:00
Fabien Potencier 977aef7172 Deprecate prefixed macro definedness checks 2026-08-27 13:32:19 +02:00
Fabien Potencier 8a37332def Fix duplicate macro deprecation wording 2026-08-27 13:32:19 +02:00
Fabien Potencier cf971e1a59 Remove lazy macro import resolution 2026-08-27 12:17:08 +02:00
Fabien Potencier 3265884e93 bug #4899 Fix Stringable keys for ArrayAccess implementations (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Fix Stringable keys for ArrayAccess implementations

This restores support for `Stringable` keys on string-keyed `ArrayAccess` implementations such as `ArrayObject` and `ArrayIterator`, while preserving object keys for `SplObjectStorage`.

The object key is attempted first and is converted to a string only when the implementation rejects it. The optimized and strict lookup paths now share the same behavior without duplicate existence checks.

Commits
-------

f3f1649955 Fix Stringable keys for ArrayAccess implementations
2026-08-27 08:42:51 +02:00
Fabien Potencier f3f1649955 Fix Stringable keys for ArrayAccess implementations 2026-08-27 08:42:47 +02:00
Fabien Potencier 609376f491 Fix repeated object destructuring evaluation 2026-08-27 07:37:11 +02:00
Fabien Potencier a3a318face Reject destructuring patterns containing no variables 2026-08-27 07:18:49 +02:00
Fabien Potencier a2b023397e Fix an empty destructuring pattern triggering a PHP fatal error instead of a SyntaxError 2026-08-23 09:50:46 +02:00
Fabien Potencier e2014eb92a Fix Traversable sequence destructuring semantics 2026-08-23 09:40:21 +02:00
Ilia Alshanetsky 9de1b3db98 Fix array destructuring from a Traversable
Sequence destructuring compiled its right-hand side straight into
array_pad(), which throws "Argument #1 must be of type array" when a
Traversable is provided:

    {% do [a, b] = items %}

with an IteratorAggregate/Generator for items crashed with a TypeError.
Coerce Traversables via iterator_to_array() before padding, matching
the behavior of the spread, merge, and slice operations which already
accept Traversables.
2026-08-22 12:36:24 -04:00
Nicolas Grekas 10c9e9946b Merge branch '3.x' into 4.x
* 3.x:
  Fix the empty comment "{##}" being lexed as a documentation comment opening
2026-08-20 20:40:40 +02:00
Pascal CESCON - Amoifr c9c3b23a77 Fix the empty comment "{##}" being lexed as a documentation comment opening 2026-08-19 19:01:11 +02:00
Fabien Potencier 8021c1a05c Fix merge conflict resolution 2026-08-19 16:46:10 +02:00
Fabien Potencier d7fc3d6dc9 Merge branch '3.x' into 4.x
* 3.x:
  Attach documentation comments to nodes

# Conflicts:
#	CHANGELOG
#	src/Lexer.php
#	src/Node/Node.php
#	src/Parser.php
#	src/Token.php
2026-08-19 16:44:35 +02:00
Fabien Potencier 6806e30474 Attach documentation comments to nodes 2026-08-19 16:41:17 +02:00
Fabien Potencier 60d3b3452a Merge branch '3.x' into 4.x
* 3.x:
  Add support for tempest/markdown in markdown-extra
  Add the include_only function to render a template without access to the current context
  Clarify duplicate macro deprecation message
  Deduplicate template error handling

# Conflicts:
#	.gitignore
#	CHANGELOG
#	extra/markdown-extra/composer.json
#	src/Extension/CoreExtension.php
#	src/Parser.php
#	src/Template.php
#	tests/Fixtures/macros/duplicate_definition.legacy.test
2026-08-16 10:57:50 +02:00
Fabien Potencier dc8f96df3e Add the include_only function to render a template without access to the current context 2026-08-11 20:58:31 +02:00
Fabien Potencier 6fafa104c4 tidy #4883 Clarify duplicate macro deprecation message (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Clarify duplicate macro deprecation message

Commits
-------

8ca4866a95 Clarify duplicate macro deprecation message
2026-08-03 21:22:23 +02:00
Fabien Potencier e1bc2814d5 tidy #4882 Deduplicate template error handling (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deduplicate template error handling

Commits
-------

e62abbf528 Deduplicate template error handling
2026-08-03 18:11:07 +02:00
Fabien Potencier 8ca4866a95 Clarify duplicate macro deprecation message 2026-08-03 17:35:03 +02:00
Fabien Potencier e62abbf528 Deduplicate template error handling 2026-08-03 17:28:46 +02:00
Fabien Potencier 93b00ee3c9 Merge branch '3.x' into 4.x
* 3.x:
  Nested macro imports

# Conflicts:
#	CHANGELOG
#	src/MacroNamespace.php
#	src/Node/MacrosNode.php
#	src/Parser.php
#	tests/Extension/SandboxStateChangeTest.php
#	tests/Node/MacrosTest.php
2026-08-03 10:34:02 +02:00
Fabien Potencier b53e100444 Nested macro imports 2026-08-03 10:30:32 +02:00
Fabien Potencier d5e2f249d2 Remove deprecated macro defined test syntax 2026-07-31 12:18:02 +02:00
Fabien Potencier ab8e41b49b Merge branch '3.x' into 4.x
* 3.x:
  Deprecate using parentheses when testing a macro with the defined test

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	src/ExpressionParser/Infix/DotExpressionParser.php
#	src/ExpressionParser/Infix/FunctionExpressionParser.php
#	src/ExpressionParser/Infix/IsExpressionParser.php
#	tests/Fixtures/macros/call_without_parentheses.legacy.test
#	tests/ParserTest.php
2026-07-31 12:15:12 +02:00
Fabien Potencier 34d9c67d38 Deprecate using parentheses when testing a macro with the defined test 2026-07-31 12:09:23 +02:00
Fabien Potencier ce013c063e Remove deprecated code 2026-07-30 14:14:10 +02:00
Fabien Potencier efd847f456 Fix merge conflict resolution 2026-07-30 14:04:07 +02:00
Fabien Potencier 986a765019 Merge branch '3.x' into 4.x
* 3.x:
  Redesign macro calls and argument handling

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	src/ExpressionParser/Infix/ArgumentsTrait.php
#	src/ExpressionParser/Infix/DotExpressionParser.php
#	src/ExpressionParser/Infix/FunctionExpressionParser.php
#	src/Extension/CoreExtension.php
#	src/Node/Expression/MacroReferenceExpression.php
#	src/Node/Expression/MethodCallExpression.php
#	src/Node/Expression/TempNameExpression.php
#	src/Node/MacroNode.php
#	src/Node/ModuleNode.php
#	src/Template.php
#	tests/Fixtures/macros/call_without_parentheses.legacy.test
#	tests/Node/Expression/MacroReferenceTest.php
#	tests/Node/MacroTest.php
2026-07-30 14:02:30 +02:00
Fabien Potencier d7f8b4eb1c Redesign macro calls and argument handling 2026-07-30 13:53:24 +02:00
Fabien Potencier b34f022583 Remove deprecated code 2026-07-30 13:52:37 +02:00
Fabien Potencier feffcb7df8 Fix merge conflict resolution 2026-07-30 13:32:38 +02:00
Fabien Potencier 3197df7b5e Merge branch '3.x' into 4.x
* 3.x:
  Make the sandbox a first-class citizen with a dedicated Sandbox class

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	doc/tags/sandbox.rst
#	phpstan-baseline.neon
#	src/Extension/CoreExtension.php
#	src/Extension/SandboxExtension.php
#	src/Sandbox/SecurityPolicy.php
2026-07-30 13:04:50 +02:00
Fabien Potencier b762bc94b9 Make the sandbox a first-class citizen with a dedicated Sandbox class 2026-07-30 12:05:47 +02:00
Fabien Potencier 096da67e7b Remove deprecated macro calls without parentheses 2026-07-28 16:39:05 +02:00
Fabien Potencier 9b42c9bd3d Merge branch '3.x' into 4.x
* 3.x:
  Deprecate macro calls without parentheses

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
2026-07-28 16:26:41 +02:00
Fabien Potencier ad305b414e Deprecate macro calls without parentheses 2026-07-28 16:13:23 +02:00
Fabien Potencier 8bfb29b953 Remove deprecated code 2026-07-28 14:52:35 +02:00
Fabien Potencier 80df3b5f63 Merge branch '3.x' into 4.x
* 3.x:
  Rename macro variable AST nodes

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	src/ExpressionParser/Infix/DotExpressionParser.php
#	src/Node/Expression/Variable/TemplateVariable.php
#	src/Node/ImportNode.php
#	src/Parser.php
2026-07-28 14:47:56 +02:00
Fabien Potencier be36fee09e Rename macro variable AST nodes 2026-07-28 11:53:50 +02:00
Fabien Potencier 2100129669 Remove deprecated code 2026-07-28 10:13:16 +02:00