diff --git a/library/Icinga/Data/Tree/Node.php b/library/Icinga/Data/Tree/Node.php new file mode 100644 index 000000000..db3a49749 --- /dev/null +++ b/library/Icinga/Data/Tree/Node.php @@ -0,0 +1,62 @@ +value = $value; + } + + public function getValue() + { + return $this->value; + } + + public function appendChild($value) + { + $child = new static($value); + $this->push($child); + return $child; + } + + public function hasChildren() + { + $current = $this->current(); + if ($current === null) {; + $current = $this; + } + return ! $current->isEmpty(); + } + + public function getChildren() + { + $current = $this->current(); + if ($current === null) {; + $current = $this; + } + return $current; + } + + public function findNodeBy($callback) + { + if (! is_callable($callback)) { + throw new RuntimeException(); + } + foreach (new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST) as $node) { + if (call_user_func($callback, $node)) { + return $node; + } + } + return null; + } +}