Skip to content

Commit e5d24ca

Browse files
committed
removed RecursiveComponentIterator, replaced by generator
1 parent 869a0fc commit e5d24ca

File tree

4 files changed

+22
-53
lines changed

4 files changed

+22
-53
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "8.2 - 8.5",
19-
"nette/utils": "^4.0"
19+
"nette/utils": "^4.0.10"
2020
},
2121
"require-dev": {
2222
"nette/tester": "^2.5",

src/ComponentModel/Container.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,13 @@ final public function getComponents(): iterable
186186
{
187187
$filterType = func_get_args()[1] ?? null;
188188
if (func_get_args()[0] ?? null) { // back compatibility
189-
$iterator = new RecursiveComponentIterator($this->components);
190-
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
191-
if ($filterType) {
192-
$iterator = new \CallbackFilterIterator($iterator, fn($item) => $item instanceof $filterType);
193-
}
194-
return $iterator;
189+
return Nette\Utils\Iterables::repeatable(function () use ($filterType) {
190+
foreach ($this->getComponentTree() as $component) {
191+
if (!$filterType || $component instanceof $filterType) {
192+
yield $component->getName() => $component;
193+
}
194+
}
195+
});
195196
}
196197

197198
return $filterType

src/ComponentModel/RecursiveComponentIterator.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/ComponentModel/Container.getComponents.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ Assert::same([
5757
'two',
5858
'button1',
5959
], array_keys(iterator_to_array($list)));
60+
// again
61+
Assert::same([
62+
'one',
63+
'inner',
64+
'inner2',
65+
'button2',
66+
'two',
67+
'button1',
68+
], array_keys(iterator_to_array($list)));
6069

6170

6271
// Recursive & filter I
@@ -65,6 +74,11 @@ Assert::same([
6574
'button2',
6675
'button1',
6776
], array_keys(iterator_to_array($list)));
77+
// again
78+
Assert::same([
79+
'button2',
80+
'button1',
81+
], array_keys(iterator_to_array($list)));
6882

6983

7084
// Recursive & filter II

0 commit comments

Comments
 (0)