Skip to content

Commit 084be27

Browse files
committed
fixed support for IteratorAggregate in the filter filter
1 parent 3d95ffe commit 084be27

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Extension/CoreExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,10 @@ function twig_array_filter($array, $arrow)
16961696
return array_filter($array, $arrow);
16971697
}
16981698

1699+
while ($array instanceof \IteratorAggregate) {
1700+
$array = $array->getIterator();
1701+
}
1702+
16991703
return new \CallbackFilterIterator($array, $arrow);
17001704
}
17011705

test/Twig/Tests/Fixtures/filters/filter.test

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818
{% for k, v in it|filter((v) => v > offset) -%}
1919
{{ k }} = {{ v }}
2020
{% endfor %}
21+
22+
{% for k, v in ita|filter(v => v > offset) -%}
23+
{{ k }} = {{ v }}
24+
{% endfor %}
2125
--DATA--
22-
return ['it' => new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8])]
26+
return [
27+
'it' => new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8]),
28+
'ita' => new IteratorAggregateStub(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8]),
29+
]
2330
--EXPECT--
2431
1 = 5
2532
3 = 4
@@ -34,3 +41,6 @@ d = 8
3441

3542
c = 5
3643
d = 8
44+
45+
c = 5
46+
d = 8

0 commit comments

Comments
 (0)