Ejemplo n.º 1
0
 public function testItemOrder()
 {
     $config = ['a', 'b'];
     $itemsInReverseOrder = ['b' => $b = new Node(), 'a' => $a = new Node()];
     $builder = new TreeBuilder();
     $tree = $builder->build($config, $itemsInReverseOrder);
     self::assertTrue($b === array_pop($tree));
 }
Ejemplo n.º 2
0
 /**
  * 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();
             }
         }
     }
 }