From 61fd8caa93950be39eb06fccfef8a9a4512f1145 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 27 Jan 2017 15:32:08 +0100 Subject: [PATCH] BpNode: add a new helper method --- library/Businessprocess/BpNode.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/library/Businessprocess/BpNode.php b/library/Businessprocess/BpNode.php index cef62989..d83aa9de 100644 --- a/library/Businessprocess/BpNode.php +++ b/library/Businessprocess/BpNode.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Businessprocess; use Icinga\Exception\ConfigurationError; +use Icinga\Exception\NotFoundError; use Icinga\Module\Businessprocess\Exception\NestingError; class BpNode extends Node @@ -121,7 +122,7 @@ public function getProblematicChildren() { $problems = array(); - foreach ($this->children as $child) { + foreach ($this->getChildren() as $child) { if ($child->isProblem() || ($child instanceof BpNode && $child->hasProblems()) ) { @@ -444,6 +445,22 @@ public function getChildBpNodes() return $children; } + /** + * @param $childName + * @return Node + * @throws NotFoundError + */ + public function getChildByName($childName) + { + foreach ($this->getChildren() as $name => $child) { + if ($name === $childName) { + return $child; + } + } + + throw new NotFoundError('Trying to get missing child %s', $childName); + } + protected function assertNumericOperator() { if (! is_numeric($this->operator)) {