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: */
11:
12: namespace Nette;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Generic recursive iterator.
20: *
21: * @author David Grudl
22: */
23: class GenericRecursiveIterator extends \IteratorIterator implements \RecursiveIterator, \Countable
24: {
25:
26: /**
27: * Has the current element has children?
28: * @return bool
29: */
30: public function hasChildren()
31: {
32: $obj = $this->current();
33: return ($obj instanceof \IteratorAggregate && $obj->getIterator() instanceof \RecursiveIterator) || $obj instanceof \RecursiveIterator;
34: }
35:
36:
37:
38: /**
39: * The sub-iterator for the current element.
40: * @return \RecursiveIterator
41: */
42: public function getChildren()
43: {
44: $obj = $this->current();
45: return $obj instanceof \IteratorAggregate ? $obj->getIterator() : $obj;
46: }
47:
48:
49:
50: /**
51: * Returns the count of elements.
52: * @return int
53: */
54: public function count()
55: {
56: return iterator_count($this);
57: }
58:
59: }
60: