1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: * @package Nette\Iterators
7: */
8:
9:
10:
11: /**
12: * Generic recursive iterator.
13: *
14: * @author David Grudl
15: * @package Nette\Iterators
16: */
17: class NGenericRecursiveIterator extends IteratorIterator implements RecursiveIterator, Countable
18: {
19:
20: /**
21: * Has the current element has children?
22: * @return bool
23: */
24: public function hasChildren()
25: {
26: $obj = $this->current();
27: return ($obj instanceof IteratorAggregate && $obj->getIterator() instanceof RecursiveIterator)
28: || $obj instanceof RecursiveIterator;
29: }
30:
31:
32: /**
33: * The sub-iterator for the current element.
34: * @return RecursiveIterator
35: */
36: public function getChildren()
37: {
38: $obj = $this->current();
39: return $obj instanceof IteratorAggregate ? $obj->getIterator() : $obj;
40: }
41:
42:
43: /**
44: * Returns the count of elements.
45: * @return int
46: */
47: public function count()
48: {
49: return iterator_count($this);
50: }
51:
52: }
53: