/** * Sets the parent node. * * @param AbstractNode $parent * @return $this * @throws CircularException */ public function setParent(AbstractNode $parent) { // check integrity if ($this->isDescendant($parent->id())) { throw new CircularException('Can not add descendant "' . $parent->id() . '" as my parent.'); } // remove from old parent if (!is_null($this->parent)) { if ($this->parent->id() == $parent->id()) { // already the parent return $this; } $this->parent->removeChild($this->id); } $this->parent = $parent; // assign child to parent $this->parent->addChild($this); //clear any cache $this->clear(); return $this; }