Skip to content

Commit e5b53df

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

File tree

2 files changed

+14
-52
lines changed

2 files changed

+14
-52
lines changed

src/ComponentModel/Container.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,7 @@ 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 $this->getComponentsRecursive($filterType);
195190
}
196191

197192
return $filterType
@@ -200,6 +195,19 @@ final public function getComponents(): iterable
200195
}
201196

202197

198+
private function getComponentsRecursive(?string $filterType): \Generator
199+
{
200+
foreach ($this->components as $name => $component) {
201+
if (!$filterType || $component instanceof $filterType) {
202+
yield $name => $component;
203+
}
204+
if ($component instanceof IContainer) {
205+
yield from $component->getComponentsRecursive($filterType);
206+
}
207+
}
208+
}
209+
210+
203211
/**
204212
* Retrieves the entire hierarchy of components, including all nested child components (depth-first).
205213
* @return list<IComponent>

src/ComponentModel/RecursiveComponentIterator.php

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

0 commit comments

Comments
 (0)