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