Exemple #1
0
 public function setNode(Path $path, $value, $force)
 {
     $root = $this->rootNode;
     $mounted = false;
     TraverseArray::set($root, $path, $value, $force, true, function ($mounterClass, $relativePath, $value, $force, $path) use(&$mounted) {
         $mounted = true;
         return $this->router->query($mounterClass)->setNode($relativePath, $value, $force);
     });
     // it has altered the copy of root node
     if (!$mounted) {
         throw new NodeReadonlyException();
     }
 }
 /** @test */
 public function it_extends_primitive_nodes_with_force()
 {
     $array = ["foo" => ["bar" => 5], "asd" => 2];
     TraverseArray::set($array, "asd.boo", 42, true);
     $this->assertEquals(["foo" => ["bar" => 5], "asd" => ["boo" => 42]], $array);
 }
 /**
  * Do the actual javascript passing. Called only from master.blade.php
  */
 public function doPassing()
 {
     $data = ["tree" => [], "pointers" => []];
     // foreach node to pass
     for ($i = 0; $i < count($this->pathsToPass); $i++) {
         // add the node to the tree
         TraverseArray::set($data["tree"], $this->pathsToPass[$i], $this->getRaw($this->pathsToPass[$i], []));
         // get all pointers under that node
         $pointers = $this->pointersLocatedUnder($this->pathsToPass[$i]);
         foreach ($pointers as $p) {
             // add all nodes that those pointers point to
             // and they are gonna be pushed at the end of the passing array
             // and thus passed later in this cycle
             $this->passNode($p->target);
             // pass those pointers
             $data["pointers"][] = ["id" => $p->id(), "location" => $p->location()->toString(), "target" => $p->target()->toString()];
         }
     }
     return $data;
 }
Exemple #4
0
 public function setNode(Path $path, $value, $force)
 {
     // cannot set value of the entire gds data system
     if ($path->root()) {
         throw new NodeReadonlyException();
     }
     // load the row we're gonna be working with
     try {
         $this->getRow($path[0]);
     } catch (TableRowNotFoundException $e) {
         // create
         $this->loadedRows[$path[0]] = [];
         // remove from rowsToRemove if present
         if (($i_toRemove = array_search($path[0], $this->rowsToRemove)) !== false) {
             unset($this->rowsToRemove[$i_toRemove]);
         } else {
             // when saving, create instead (insert, not update)
             $this->rowsToCreate[] = $path[0];
         }
     }
     // update row
     TraverseArray::set($this->loadedRows, $path, $value, $force);
     // unsaved
     if (!in_array($path[0], $this->unsavedRows)) {
         $this->unsavedRows[] = $path[0];
     }
 }