1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: * @package Nette\Iterators
7: */
8:
9:
10:
11: /**
12: * Callback recursive iterator filter.
13: *
14: * @author David Grudl
15: * @package Nette\Iterators
16: */
17: class NNRecursiveCallbackFilterIterator extends FilterIterator implements RecursiveIterator
18: {
19: /** @var callable */
20: private $callback;
21:
22: /** @var callable */
23: private $childrenCallback;
24:
25:
26: public function __construct(RecursiveIterator $iterator, $callback, $childrenCallback = NULL)
27: {
28: parent::__construct($iterator);
29: $this->callback = $callback === NULL ? NULL : new NCallback($callback);
30: $this->childrenCallback = $childrenCallback === NULL ? NULL : new NCallback($childrenCallback);
31: }
32:
33:
34: public function accept()
35: {
36: return $this->callback === NULL || $this->callback->invoke($this);
37: }
38:
39:
40: public function hasChildren()
41: {
42: return $this->getInnerIterator()->hasChildren()
43: && ($this->childrenCallback === NULL || $this->childrenCallback->invoke($this));
44: }
45:
46:
47: public function getChildren()
48: {
49: return new self($this->getInnerIterator()->getChildren(), $this->callback, $this->childrenCallback);
50: }
51:
52: }
53: