Merge branch '2.x' into 3.x

* 2.x:
  fixed support for IteratorAggregate in the filter filter
This commit is contained in:
Fabien Potencier
2019-05-10 08:47:14 +02:00
2 changed files with 15 additions and 1 deletions
+4
View File
@@ -1806,6 +1806,10 @@ function twig_array_filter($array, $arrow)
return array_filter($array, $arrow);
}
while ($array instanceof \IteratorAggregate) {
$array = $array->getIterator();
}
return new \CallbackFilterIterator($array, $arrow);
}
+11 -1
View File
@@ -22,8 +22,15 @@
{% for k, v in it|filter((v) => v > offset) -%}
{{ k }} = {{ v }}
{% endfor %}
{% for k, v in ita|filter(v => v > offset) -%}
{{ k }} = {{ v }}
{% endfor %}
--DATA--
return ['it' => new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8])]
return [
'it' => new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8]),
'ita' => new IteratorAggregateStub(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8]),
]
--EXPECT--
1 = 5
3 = 4
@@ -40,3 +47,6 @@ c = 5
c = 5
d = 8
c = 5
d = 8