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: 31: 32: 33: 34:
35: public function __construct(RecursiveIterator $iterator, $callback, $childrenCallback = NULL)
36: {
37: parent::__construct($iterator);
38: $this->callback = $callback === NULL ? NULL : callback($callback);
39: $this->childrenCallback = $childrenCallback === NULL ? NULL : callback($childrenCallback);
40: }
41:
42:
43:
44: public function accept()
45: {
46: return $this->callback === NULL || $this->callback->invoke($this);
47: }
48:
49:
50:
51: public function hasChildren()
52: {
53: return $this->getInnerIterator()->hasChildren()
54: && ($this->childrenCallback === NULL || $this->childrenCallback->invoke($this));
55: }
56:
57:
58:
59: public function getChildren()
60: {
61: return new self($this->getInnerIterator()->getChildren(), $this->callback, $this->childrenCallback);
62: }
63:
64: }
65: