1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19: 20:
21: class NNRecursiveCallbackFilterIterator extends FilterIterator implements RecursiveIterator
22: {
23:
24: private $callback;
25:
26:
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 NCallback($callback);
34: $this->childrenCallback = $childrenCallback === NULL ? NULL : new NCallback($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: