Commit Graph

6709 Commits

Author SHA1 Message Date
Fabien Potencier 525461feb1 Fix CS 2024-08-15 20:26:39 +02:00
Fabien Potencier 62cc16f548 Merge branch '3.x' into 4.x
* 3.x:
  Remove remaining const optimizations
2024-08-15 20:26:12 +02:00
Fabien Potencier 3c7469ec09 minor #4204 Remove remaining const optimizations (smnandre)
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
2024-08-15 20:22:54 +02:00
Simon André c662e0ce27 Remove remaining const optimizations
After #4198 some `Token::` const optimization remains.

This PR remove them.. **in case** it was not intended
2024-08-15 19:11:55 +02:00
Fabien Potencier 3b38f7c587 Simplify code 2024-08-14 23:45:21 +02:00
Fabien Potencier 7f45529f52 Merge branch '3.x' into 4.x
* 3.x:
  Fix RawFilter
2024-08-14 23:43:34 +02:00
Fabien Potencier 72d6d9c9c5 bug #4203 Fix RawFilter (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix RawFilter

Commits
-------

397b7c47 Fix RawFilter
2024-08-14 23:43:27 +02:00
Fabien Potencier 397b7c4782 Fix RawFilter 2024-08-14 23:42:25 +02:00
Fabien Potencier eaf04e53f0 Remove deprecated code 2024-08-14 23:34:13 +02:00
Fabien Potencier abee6fc583 Merge branch '3.x' into 4.x
* 3.x:
  Move FunctionExpression/FilterExpression/TestExpression attributes from compilation time to parsing time
  Cleanup the implementation of the defined test for constants
2024-08-14 23:07:43 +02:00
Fabien Potencier fb96eed2c6 feature #4184 Move FunctionExpression/FilterExpression/TestExpression attributes from compilation time to parsing time (fabpot)
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
2024-08-14 22:55:12 +02:00
Fabien Potencier 3156d8093e Move FunctionExpression/FilterExpression/TestExpression attributes from compilation time to parsing time 2024-08-14 18:45:35 +02:00
Fabien Potencier 85a5b7c2d1 minor #4202 Cleanup the implementation of the defined test for constants (fabpot)
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
2024-08-13 22:43:21 +02:00
Fabien Potencier 6ecd1f1350 Cleanup the implementation of the defined test for constants 2024-08-13 22:40:15 +02:00
Fabien Potencier 3ed166f0e4 minor #4201 Disable the drupal integration tests in the 4.x branch (stof)
This PR was merged into the 4.x branch.

Discussion
----------

Disable the drupal integration tests in the 4.x branch

Drupal uses the AbstractNodeVisitor which is deprecated in 3.x and removed in 4.x, so the job fails all the time. This should be re-enabled once Drupal can be tested against Twig 4.x.

Commits
-------

1d71e28a Disable the drupal integration tests in the 4.x branch
2024-08-13 18:39:08 +02:00
Fabien Potencier d7df8844e0 Merge branch '3.x' into 4.x
* 3.x:
  Add missing method in TwigCallableInterface
  Fix TwigCallableInterface
  Simplify code
  Make various optimization for dynamic Twig callables
2024-08-13 18:37:32 +02:00
Christophe Coevoet 1d71e28a0a Disable the drupal integration tests in the 4.x branch
Drupal uses the AbstractNodeVisitor which is deprecated in 3.x and removed in 4.x, so the job fails all the time.
This should be re-enabled once Drupal can be tested against Twig 4.x.
2024-08-13 16:39:04 +02:00
Fabien Potencier d3ab783595 Add missing method in TwigCallableInterface 2024-08-13 11:28:14 +02:00
Fabien Potencier 21df1ad782 Fix TwigCallableInterface 2024-08-12 11:03:48 +02:00
Fabien Potencier 1da763408b Simplify code 2024-08-12 10:49:48 +02:00
Fabien Potencier 66ace94b06 feature #4194 Make various optimizations for dynamic Twig callables (fabpot)
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
2024-08-12 10:37:09 +02:00
Fabien Potencier 148d3e079d Make various optimization for dynamic Twig callables 2024-08-12 09:45:32 +02:00
Fabien Potencier c3791fe986 Merge branch '3.x' into 4.x
* 3.x:
  Remove const optimization
2024-08-12 09:43:20 +02:00
Fabien Potencier 2fa8a24e0b minor #4198 Remove const optimization (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Remove const optimization

Closes #4197

Commits
-------

cd0ac3cc Remove const optimization
2024-08-12 09:42:24 +02:00
Fabien Potencier cd0ac3cc0a Remove const optimization 2024-08-12 09:40:52 +02:00
Fabien Potencier 91f29731d4 Merge branch '3.x' into 4.x
* 3.x:
  Optimize stripcslashes
  (minor) Prefer `className` over `classname`
  Remove escape
  Deprecate unnecessary escape characters
  Micro-micro optimization
  Simplify tests
2024-08-12 09:28:43 +02:00
Fabien Potencier 93e66ad141 minor #4196 Optimize stripcslashes (ruudk)
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
2024-08-12 09:25:01 +02:00
Ruud Kamphuis bc6e36dee9 Optimize stripcslashes 2024-08-12 09:24:57 +02:00
Fabien Potencier 4e730d46ca minor #4195 (minor) Prefer className over classname (smnandre)
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`
2024-08-12 09:19:28 +02:00
Simon André 03012f190f (minor) Prefer className over classname
For consistency with how it's written in the tested classes.
2024-08-12 08:16:07 +02:00
Fabien Potencier 5541e6a6fc minor #4193 Remove escape (ruudk)
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
2024-08-11 22:46:36 +02:00
Ruud Kamphuis 8ef12588ea Remove escape 2024-08-11 18:59:31 +02:00
Fabien Potencier 110c1ab669 feature #4176 Deprecate unnecessary escape characters (ruudk)
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
2024-08-11 18:16:33 +02:00
Ruud Kamphuis c6656cf5d0 Deprecate unnecessary escape characters
See #4123 #2712

This allows to change the implementation in v4 so that we no longer have to escape backslashes.
2024-08-11 16:21:05 +02:00
Fabien Potencier e1b099707c Micro-micro optimization 2024-08-11 12:56:40 +02:00
Fabien Potencier 8a8f22131c Simplify tests 2024-08-10 18:25:26 +02:00
Fabien Potencier 4a2fb5b460 Merge branch '3.x' into 4.x
* 3.x:
  Add the notion of a Twig callable
  Drop support for 8.0
  Add more tests to the Lexer
  Add a note about how to escape a string interpolation in a string
  Bump version to 3.12
  Implement the enum_cases function
  Remove deprecation arg
  Fix integration tests when a test has more than on data/expect section and deprecations
  Bump version
  Prepare the 3.11.0 release
  Update CHANGELOG
2024-08-10 18:01:24 +02:00
Fabien Potencier ff337fe45c feature #4192 Add the notion of a Twig callable (fabpot)
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
2024-08-10 17:56:11 +02:00
Fabien Potencier 84bc23af93 Add the notion of a Twig callable 2024-08-10 17:55:26 +02:00
Fabien Potencier c2dd532c72 feature #4191 Drop support for 8.0 (fabpot)
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
2024-08-10 12:42:38 +02:00
Fabien Potencier c070cd719c Drop support for 8.0 2024-08-10 12:32:24 +02:00
Fabien Potencier 1870a61773 minor #4190 Add more tests to the Lexer (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add more tests to the Lexer

Commits
-------

38250b91 Add more tests to the Lexer
2024-08-10 12:19:59 +02:00
Fabien Potencier 346749b8c1 minor #4189 Add a note about how to escape a string interpolation in a string (fabpot)
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
2024-08-10 12:19:46 +02:00
Fabien Potencier 38250b91ca Add more tests to the Lexer 2024-08-10 12:17:25 +02:00
Fabien Potencier 38e47a3e94 Add a note about how to escape a string interpolation in a string 2024-08-10 11:32:28 +02:00
Fabien Potencier 221e62cf63 Bump version to 3.12 2024-08-10 11:01:45 +02:00
Fabien Potencier aed4990615 feature #4177 Implement the enum_cases function (stof)
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
2024-08-10 10:40:52 +02:00
Christophe Coevoet ff4d01f940 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.
2024-08-09 21:21:58 +02:00
Fabien Potencier b3f953c132 bug #4187 Fix integration tests when a test has more than on data/expect section and deprecations (fabpot)
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
2024-08-09 18:13:27 +02:00
Fabien Potencier 5550140931 Remove deprecation arg 2024-08-09 18:02:41 +02:00