This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Fix IntlExtension::formatDateTime use of date formatter prototype
See https://github.com/twigphp/intl-extra/pull/6 for more details
Commits
-------
c75762c3 Fix IntlExtension::formatDateTime use of date formatter prototype
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
Fix premature loop exit in Security Policy lookup of allowed methods/properties
The current security policy logic exits too soon when checking permissions for allowed classes and their methods/properties, causing false negatives in situations involving classes related by inheritance.
Consider the following configuration:
```
'methods' => [
'App\BasicCollection' => ['sortAlphabetically'],
'App\AdvancedCollection'=> ['sortByTimestamp'],
],
```
where `AdvancedCollection` is a subclass of `BasicCollection`, and `mylist` is an instance of `AdvancedCollection`
If you try to call `{{ mylist.sortByTimestamp() }}`, the current code will first match `mylist` against `App\BasicCollection`. Since `sortByTimestamp` is not an allowed method for `App\BasicCollection`, the code will exit the loop and incorrectly deny access. It will never get to checking `App\AdvancedCollection`.
Note that reordering classes in the config can't solve this issue. If you flipped the order, then it would fail for `{{ mylist.sortAlphabetically() }}` instead.
This pull request fixes the issue by only exiting the loop early when both the class and method/property match.
Commits
-------
5e1838db Fix premature loop exit in Security Policy lookup of allowed methods/properties
This PR was merged into the 3.x branch.
Discussion
----------
Compile Elvis operator into Elvis operator `?:`
When using ternary operator without "then" part, the "condition" part is evaluated twice, which is inconsistent with how PHP works.
The Twig template `A ?: B` is currently compiled as `A ? A : B` in PHP. This PR change it to `A ?: B`.
If `A` is a complex expression, it improves performance to only execute the expression once.
If `A` is has a side effect (like updating a variable), the expression being executed twice could result in a bug. ([example in PHP](https://3v4l.org/LWZLR))
Example with ``@WebProfiler`/Collector/form.html.twig` [line 9](https://github.com/symfony/symfony/blob/e6d1ed4edb5ae197ec7d25ddaf64cfa456229504/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig#L9) (see deep [diff](https://www.diffchecker.com/jOm3dE13/))
```twig
{{ collector.data.nb_errors ?: collector.data.forms|length }}
```
Previous compilation:
```php
echo twig_escape_filter($this->env, (((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })())) ? ((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })())) : (twig_get_attribute($this->env, $this->source, (isset($context["collector"]) || array_key_exists("collector", $context) ? $context["collector"] : (function () { throw new RuntimeError('Variable "collector" does not exist.', 9, $this->source); })()), "countDefines", [], "any", false, false, false, 9))), "html", null, true);
```
After this change:
```php
echo twig_escape_filter($this->env, ((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })()) ?: twig_get_attribute($this->env, $this->source, (isset($context["collector"]) || array_key_exists("collector", $context) ? $context["collector"] : (function () { throw new RuntimeError('Variable "collector" does not exist.', 9, $this->source); })()), "countDefines", [], "any", false, false, false, 9)), "html", null, true);
```
Commits
-------
fb0d7495 Compile Elvis operator with Elvis operator
This PR was merged into the 3.x branch.
Discussion
----------
Update signature to acknowledge a TemplateWrapper
`$name` legitimately can be of type `Twig\TemplateWrapper`. This is already considered in line 1331. This PR updates the method signature in the PHPDoc.
This PR is necessary because other developers may rely on the signature, see contao/contao#6169.
Commits
-------
b0cabc09 Update signature to acknowledge a TemplateWrapper
This PR was merged into the 3.x branch.
Discussion
----------
Use PHP 8.0 functions with polyfill
Backport some changes from #3881 into 3.x using `symfony/polyfill-php80`.
- `str_starts_with`
- `str_ends_with`
- `str_contains`
- `get_debug_type`
Benefits:
- Less conflicts when both 3.x and 4.x branches will be maintained.
- Performance gain for PHP 8.0+ ([83,7% of installs](https://packagist.org/packages/twig/twig/php-stats#3))
Commits
-------
1d5c0928 Use PHP 8.0 functions with polyfill
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Use PHP 7.1 features : `is_iterable`, `??` and `?:`
Apply the following changes with rector, compatible with PHP 7.1:
```php
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/doc',
__DIR__ . '/tests',
__DIR__ . '/extra',
]);
$rectorConfig->rule(\Rector\Php53\Rector\Ternary\TernaryToElvisRector::class);
$rectorConfig->rule(\Rector\Php70\Rector\Ternary\TernaryToNullCoalescingRector::class);
$rectorConfig->rule(\Rector\Php71\Rector\BooleanOr\IsIterableRector::class);
};
```
Commits
-------
991f518d Replace calls to twig_test_iterable to is_iterable
6ca0d773 Convert Ternary to Elvis or Null Coalescing
cb8a8247 Use is_iterable when possible
This PR was merged into the 3.x branch.
Discussion
----------
Remove `TemplateWrapper::render()` 2nd parameter not used
The 2nd virtual parameter of `TemplateWrapper::render()` was added by #2805.
`Template::render()` don't define and don't use this 2nd parameter.
Running the test suite, this method never get more than 1 parameter (I assumed it could be used by the compiled Template via the backtrace, but it isn't).
Commits
-------
c56b87b4 Remove TemplateWrapper::render 2nd parameter not used
This PR was merged into the 3.x branch.
Discussion
----------
Remove unused variables and unreachable code
I did some archaeology to find the origin of each useless line of code. Details in comments.
Commits
-------
6d715e20 Remove unused variables and unreachable code
This PR was merged into the 3.x branch.
Discussion
----------
range example leads to Array to string conversion exception
In templates documentation, a range example is displayed and leads to an Array to string conversion exception without a join filter.
Commits
-------
53496507 range example leads to Array to string conversion exception
This PR was merged into the 3.x branch.
Discussion
----------
fix `NumberFormatter::TYPE_CURRENCY` being deprecated in PHP 8.3
It was never used anyway (by Twig and by PHP), so removing it should not have any side-effects.
Commits
-------
223ba6ec fix `NumberFormatter::TYPE_CURRENCY` being deprecated in PHP 8.3
This PR was merged into the 3.x branch.
Discussion
----------
Add `Twiggy` extension for VS Code to docs.
Commits
-------
81799a74 Add `Twiggy` extension for VS Code to docs.
This PR was merged into the 3.x branch.
Discussion
----------
allow Symfony 7 packages to be installed
Commits
-------
b8b0c396 allow Symfony 7 packages to be installed
This PR was submitted for the 3.x branch but it was merged into the 2.x branch instead.
Discussion
----------
Add `Twig Language Server` and `Modern Twig` extension to docs
Commits
-------
a949600c Add `Twig Language Server` and `Modern Twig` extension to docs