1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://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\Iterators;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Generic recursive iterator.
20: *
21: * @author David Grudl
22: */
23: class Recursor 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)
34: || $obj instanceof \RecursiveIterator;
35: }
36:
37:
38:
39: /**
40: * The sub-iterator for the current element.
41: * @return \RecursiveIterator
42: */
43: public function getChildren()
44: {
45: $obj = $this->current();
46: return $obj instanceof \IteratorAggregate ? $obj->getIterator() : $obj;
47: }
48:
49:
50:
51: /**
52: * Returns the count of elements.
53: * @return int
54: */
55: public function count()
56: {
57: return iterator_count($this);
58: }
59:
60: }
61: