This PR was squashed before being merged into the 1.x branch (closes#3004).
Discussion
----------
Fix support for PHP 7.4
Commits
-------
f958bd1e fixed deprecation under PHP 7.4
1fb0f970 fixed PHP 7.4 support
7be8e944 added PHP 7.4 in Travis config
This PR was merged into the 1.x branch.
Discussion
----------
Fix support for IteratorAggregate in the filter filter
Commits
-------
084be27d fixed support for IteratorAggregate in the filter filter
This PR was merged into the 2.x branch.
Discussion
----------
Deprecate "if" conditions on "for" tags
Commits
-------
5d1d90ba deprecated "if" conditions on "for" tags
* 2.x:
fixed CS
added the key to the map and filter filters
added support for iterators
removed fn in front of arrow functions
changed arrow syntax
added "filter", "map", and "reduce" filters
simplified code
fixed CS
bumped version to 2.10
bumped version to 1.41
fixed partial output leak when a PHP fatal error occurs
fixed markup in docs
* 1.x:
added the key to the map and filter filters
added support for iterators
removed fn in front of arrow functions
changed arrow syntax
added "filter", "map", and "reduce" filters
simplified code
fixed CS
fixed partial output leak when a PHP fatal error occurs
This PR was squashed before being merged into the 1.x branch (closes#2996).
Discussion
----------
Add "filter", "map", and "reduce" filters
This PR adds support for 3 new filters: `filter`, `map`, and `reduce`. They take an arrow function as an argument (a PHP closure).
I have restricted the usage of arrow functions as much as possible as it makes no sense to support them everywhere. So, for now, they are only accepted as arguments to filters (using them as arguments to function is not supported but could be easily added if we have a use case).
The syntax is the following: `(x) => x + 3` where `(x)` is the list of arguments, `=>` starts the body, and the body is any Twig expression. Within the arrow function, the context is also available: `(x) => x + offset` works if `offset` is defined in the current context.
~~These new filters will allow us to deprecate the `if` support on the `for` tag, which does not work well with the `loop` variable:~~
```twig
{% set sizes = {xs: 34, s: 36, m: 38, l: 40, xl: 42} %}
{# before #}
{% for name, size in sizes if size < 38 %}
{{ name }} = {{ size }}
{% loop.last ? 'LAST' %} {# <--- works with this PR #}
{% endfor %}
{# after #}
{% for name, size in sizes|filter(size => size < 38) %}
{{ name }} = {{ size }}
{{ loop.last ? 'LAST' }}
{% endfor %}
```
This closes#2785
Commits
-------
5c15f897 added the key to the map and filter filters
13274bbf added support for iterators
175041e0 removed fn in front of arrow functions
dc277635 changed arrow syntax
b30bce11 added "filter", "map", and "reduce" filters
This PR was merged into the 1.x branch.
Discussion
----------
Fix partial output leak when a PHP fatal error occurs
closes#1962 (thank you @fluff for the "trick")
Commits
-------
6196fe5b fixed partial output leak when a PHP fatal error occurs
This PR was merged into the 1.x branch.
Discussion
----------
Add tests to avoid regressions (via Drupal)
Commits
-------
9c313e3c added Drupal in the CI process
This PR was merged into the 1.x branch.
Discussion
----------
Optimize context access on PHP 7.4
Commits
-------
5b5f5659 optimized context access on PHP 7.4