/** * @param Element_Interface $target the parent element * @param Element_Interface $new the newly inserted child * @return void */ protected function updateChilds($target, $new) { if (is_array($target->getChilds())) { //check in case of recursion $found = false; foreach ($target->getChilds() as $child) { if ($child->getId() == $new->getId()) { $found = true; } } if (!$found) { $target->setChilds(array_merge($target->getChilds(), array($new))); } } else { $target->setChilds(array($new)); } }