/** * Attempts to get an ancestor node by the given id. * * @param int $id * @return null|AbstractNode */ public function getAncestor($id) { if (!is_null($this->parent)) { if ($this->parent->id() == $id) { return $this->parent; } return $this->parent->getAncestor($id); } return null; }
/** * Sets the parent node. * * @param InnerNode $parent * @return $this * @throws CircularException */ public function setParent(InnerNode $parent) { // check integrity if ($this->isDescendant($parent->id())) { throw new CircularException('Can not add descendant "' . $parent->id() . '" as my parent.'); } return parent::setParent($parent); }