@@ 5-24 (lines=20) @@ | ||
2 | ||
3 | namespace Gielfeldt\Iterators; |
|
4 | ||
5 | class RecursiveCloningIterator extends CloningIterator implements \RecursiveIterator |
|
6 | { |
|
7 | public function __construct($iterator) |
|
8 | { |
|
9 | parent::__construct($iterator); |
|
10 | if (!$this->getInnerIterator() instanceof \RecursiveIterator) { |
|
11 | throw new \InvalidArgumentException('An instance of RecursiveIterator or IteratorAggregate creating it is required'); |
|
12 | } |
|
13 | } |
|
14 | ||
15 | public function hasChildren() |
|
16 | { |
|
17 | return $this->getInnerIterator()->hasChildren(); |
|
18 | } |
|
19 | ||
20 | public function getChildren() |
|
21 | { |
|
22 | return new self($this->getInnerIterator()->getChildren()); |
|
23 | } |
|
24 | } |
|
25 |
@@ 5-24 (lines=20) @@ | ||
2 | ||
3 | namespace Gielfeldt\Iterators; |
|
4 | ||
5 | class RecursiveMapIterator extends MapIterator implements \RecursiveIterator |
|
6 | { |
|
7 | public function __construct(\Traversable $iterator, callable $callback) |
|
8 | { |
|
9 | parent::__construct($iterator, $callback); |
|
10 | if (!$this->getInnerIterator() instanceof \RecursiveIterator) { |
|
11 | throw new \InvalidArgumentException('An instance of RecursiveIterator or IteratorAggregate creating it is required'); |
|
12 | } |
|
13 | } |
|
14 | ||
15 | public function hasChildren() |
|
16 | { |
|
17 | return $this->getInnerIterator()->hasChildren(); |
|
18 | } |
|
19 | ||
20 | public function getChildren() |
|
21 | { |
|
22 | return new self($this->getInnerIterator()->getChildren(), $this->callback); |
|
23 | } |
|
24 | } |
|
25 |