This PR was merged into the 3.x branch.
Discussion
----------
Add support for named arguments on special functions
Commits
-------
0c30e78b Add support for named arguments on special functions
This PR was merged into the 3.x branch.
Discussion
----------
Throw a SyntaxError exception at compile time when a Twig callable has not the minimum number of required arguments
When using named arguments, a compilation error is thrown when some required arguments are missing.
But when not using arguments, the error was thrown at runtime. This PR fixed this.
Commits
-------
0823d234 Throw a SyntaxError exception at compile time when a Twig callable has not the minimum number of required arguments
This PR was merged into the 3.x branch.
Discussion
----------
Extract a new CallableArgumentsExtractor class
Commits
-------
e1705f88 Extract a new CallableArgumentsExtractor class
This PR was merged into the 3.x branch.
Discussion
----------
Make Node::__toString() more readable
Commits
-------
b431ecad Make Node::__toString() more readable
This PR was merged into the 3.x branch.
Discussion
----------
Remove remaining const optimizations
After #4198, some Token:: constant optimizations remained.
This PR removes them.. **in case** this was not intended
Commits
-------
c662e0ce Remove remaining const optimizations
This PR was merged into the 3.x branch.
Discussion
----------
Move FunctionExpression/FilterExpression/TestExpression attributes from compilation time to parsing time
Closes#3895
Opened early to gather feedback.
Commits
-------
3156d809 Move FunctionExpression/FilterExpression/TestExpression attributes from compilation time to parsing time
This PR was merged into the 3.x branch.
Discussion
----------
Cleanup the implementation of the defined test for constants
Let's avoid modifying the `TwigFunction`.
Commits
-------
6ecd1f13 Cleanup the implementation of the defined test for constants
This PR was merged into the 3.x branch.
Discussion
----------
Make various optimizations for dynamic Twig callables
Commits
-------
148d3e07 Make various optimization for dynamic Twig callables
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Optimize stripcslashes
See https://github.com/twigphp/Twig/pull/4176#issuecomment-2283168241 by `@smnandre`
```
# Old
Benchmark 1: php bench.php
Time (mean ± σ): 1.192 s ± 0.004 s [User: 1.163 s, System: 0.009 s]
Range (min … max): 1.186 s … 1.198 s 10 runs
# New
Benchmark 1: php bench.php
Time (mean ± σ): 356.5 ms ± 1.1 ms [User: 342.0 ms, System: 7.6 ms]
Range (min … max): 354.6 ms … 358.2 ms 10 runs
```
Using bench.php:
```php
<?php
require_once __DIR__.'/vendor/autoload.php';
$string = str_repeat("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a tincidunt turpis. \\App\\Entity\\Product \World \065 App\#{var} \'quoted\' Donec pharetra enim quis erat pharetra, dignissim molestie erat laoreet. Vivamus auctor purus sed lorem vestibulum rhoncus.", 10);
$loader = new Twig\Loader\ArrayLoader([
'index.twig' => <<<EOF
{{ "$string" }}
EOF
,
]);
$twig = new Twig\Environment($loader);
for ($i = 0; $i < 10000; $i++) {
$twig->tokenize(new Twig\Source($twig->getLoader()->getSourceContext('index.twig')->getCode(), 'index.twig'));
}
```
Commits
-------
bc6e36de Optimize stripcslashes
This PR was merged into the 3.x branch.
Discussion
----------
(minor) Prefer `className` over `classname`
For consistency with how it's written in the tested classes.
Commits
-------
03012f19 (minor) Prefer `className` over `classname`
This PR was merged into the 3.x branch.
Discussion
----------
Remove escape
Interestingly this didn’t fail on the branch that introduced the change. Are we sure the integration tests work at all?
See [failing job](https://github.com/twigphp/Twig/actions/runs/10341129793) on merge to main.
Commits
-------
8ef12588 Remove escape
This PR was merged into the 3.x branch.
Discussion
----------
Deprecate unnecessary escape characters
This is a first attempt at solving #4123 and #2712.
Currently it writes the deprecations to an array in the Lexer. This is probably not the way to do it. Should we directly trigger `E_USER_DEPRECATED` errors?
/cc `@stof` `@fabpot` Let me know what you think 😊
Commits
-------
c6656cf5 Deprecate unnecessary escape characters
This PR was merged into the 3.x branch.
Discussion
----------
Add the notion of a Twig callable
Commits
-------
84bc23af Add the notion of a Twig callable
This PR was merged into the 3.x branch.
Discussion
----------
Drop support for 8.0
The most recent version of PHP 7 (7.4) was deprecated more than a year and a half ago.
We won't remove code that supports PHP 7 (as this has already been done in 4.x and there is no point in redoing the work in the 3.x branch), but we will use some new PHP 8 features in the 3.x branch from now on.
Commits
-------
c070cd71 Drop support for 8.0
This PR was merged into the 3.x branch.
Discussion
----------
Add a note about how to escape a string interpolation in a string
Commits
-------
38e47a3e Add a note about how to escape a string interpolation in a string
This PR was merged into the 3.x branch.
Discussion
----------
Implement the enum_cases function
The implementation contains an optimized implementation of the function for the common case of using a string literal as the argument. It will validate the enum existence during compilation and compile the code to use `MyEnum::cases()` directly.
Closes#3872 (it replaces it)
Relates to #3681 (it solves the case of getting the list of cases)
Note that the strict compile time validation for string literals is especially beneficial as long as escaping `\` is mandatory in our string literals (where escaping non-special characters is the same than not putting the backslash) as by experience, this is a common mistake when trying to put a PHP FQCN in a Twig string. One of the tests I added is covering exactly this kind of mistake.
Commits
-------
ff4d01f9 Implement the enum_cases function
The implementation contains an optimized implementation of the function
for the common case of using a string literal as the argument. It will
validate the enum existence during compilation and compile the code to
use `MyEnum::cases()` directly.
This PR was merged into the 3.x branch.
Discussion
----------
Fix integration tests when a test has more than on data/expect section and deprecations
Fixes#4186
As deprecations are emitted at compile time, we need to make sure templates are always compiled even when we have more than one data/expect section (in which case the templates are the same). The trick here is to add some whitespace at the end of the template.
Commits
-------
a5dc02bb Fix integration tests when a test has more than on data/expect section and deprecations