1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\ComponentModel;
9:
10:
11: /**
12: * Recursive component iterator. See Container::getComponents().
13: * @internal
14: */
15: class RecursiveComponentIterator extends \RecursiveArrayIterator implements \Countable
16: {
17: /**
18: * Has the current element has children?
19: * @return bool
20: */
21: public function hasChildren()
22: {
23: return $this->current() instanceof IContainer;
24: }
25:
26:
27: /**
28: * The sub-iterator for the current element.
29: * @return \RecursiveIterator
30: */
31: public function getChildren()
32: {
33: return $this->current()->getComponents();
34: }
35:
36:
37: /**
38: * Returns the count of elements.
39: * @return int
40: */
41: public function count()
42: {
43: return iterator_count($this);
44: }
45: }
46: