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: * @package Nette\Iterators
11: */
12:
13:
14:
15: /**
16: * Callback recursive iterator filter.
17: *
18: * @author David Grudl
19: * @package Nette\Iterators
20: */
21: class NRecursiveCallbackFilterIterator extends FilterIterator implements RecursiveIterator
22: {
23: /** @var callable */
24: private $callback;
25:
26: /** @var callable */
27: private $childrenCallback;
28:
29:
30: public function __construct(RecursiveIterator $iterator, $callback, $childrenCallback = NULL)
31: {
32: parent::__construct($iterator);
33: $this->callback = $callback === NULL ? NULL : new Callback($callback);
34: $this->childrenCallback = $childrenCallback === NULL ? NULL : new Callback($childrenCallback);
35: }
36:
37:
38:
39: public function accept()
40: {
41: return $this->callback === NULL || $this->callback->invoke($this);
42: }
43:
44:
45:
46: public function hasChildren()
47: {
48: return $this->getInnerIterator()->hasChildren()
49: && ($this->childrenCallback === NULL || $this->childrenCallback->invoke($this));
50: }
51:
52:
53:
54: public function getChildren()
55: {
56: return new self($this->getInnerIterator()->getChildren(), $this->callback, $this->childrenCallback);
57: }
58:
59: }
60: