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