/** * Builds tree based on its nodes registry and hierarchy configuration * if structure update required. */ public function build() { if ($this->updateRequired) { $this->updateRequired = false; foreach ($this->nodes as $node) { if ($node->parent()) { $node->unlock()->detach(); } } $this->root->addChildren($this->builder->build($this->hierarchy, $this->nodes->toArray())); foreach ($this->nodes as $node) { if ($node->parent() === $this->root || $this->nodes->contains($node->parent())) { $node->lock(); } } } }
private function checkParentRelation(ParentNodeInterface $parent = null) { if ($parent === null) { throw new NoParentException(); } if (!$parent->isWritable()) { throw new ReadonlyNodeModifyException(); } if ($this->isLocked()) { throw new LockedNodeException(); } }