Ejemplo n.º 1
0
 /** @test */
 public function it_substitutes_mounter_points()
 {
     $array = ["foo" => ["@mount" => "MounterClassName"]];
     $out = TraverseArray::get($array, "", null, true, function ($mounterClass, $relativePath, $default, $path) {
         return "ValueFromMounter";
     });
     $this->assertEquals(["foo" => "ValueFromMounter"], $out);
     // =======
     $out = TraverseArray::get($array, "foo", null, true, function ($mounterClass, $relativePath, $default, $path) {
         return "ValueFromMounter";
     });
     $this->assertEquals("ValueFromMounter", $out);
 }
Ejemplo n.º 2
0
 public function removeNode(Path $path)
 {
     $root = $this->rootNode;
     $mounted = false;
     $out = TraverseArray::remove($root, $path, true, function ($mounterClass, $relativePath, $path) use(&$mounted) {
         $mounted = true;
         return $this->router->query($mounterClass)->removeNode($relativePath);
     });
     // it has altered the copy of root node
     if (!$mounted) {
         throw new NodeReadonlyException();
     }
     return $out;
 }
Ejemplo n.º 3
0
 /**
  * Set value to a single node
  */
 protected function setNode($path, $nodeTree)
 {
     // make sure we have the given node on tree
     if (!TraverseArray::has($nodeTree, $path)) {
         throw new MyceliumException("Inconsistent data with set-paths.");
     }
     // get the value
     $value = TraverseArray::get($nodeTree, $path);
     // set the value
     try {
         // try without forcing first
         try {
             $this->mycelium->set($path, $value);
         } catch (ExtendingPrimitiveNodeException $e) {
             // ok, let's force it
             $this->mycelium->set($path, $value, true);
             // log that we had to force
             Log::notice("When saving mycelium node, force was needed.", ["path" => $path]);
         }
     } catch (Exception $e) {
         throw new MyceliumException("An exception has been raised during node setting.");
     }
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 public function removeNode(Path $path)
 {
     // cannot remove 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) {
         return false;
     }
     // removing an entire row
     if ($path->length() == 1) {
         // remove from loaded rows
         if (array_key_exists($path[0], $this->loadedRows)) {
             unset($this->loadedRows[$path[0]]);
         }
         // remove from unsaved rows
         if (($i = array_search($path[0], $this->unsavedRows)) !== false) {
             unset($this->unsavedRows[$i]);
         }
         // remove from rows to create
         if (($i_toCreate = array_search($path[0], $this->rowsToCreate)) !== false) {
             unset($this->rowsToCreate[$i_toCreate]);
         }
         // add to rows to remove, but only if it wasn't in rows to create
         if (!in_array($path[0], $this->rowsToRemove) && $i_toCreate === false) {
             $this->rowsToRemove[] = $path[0];
         }
         // successfully removed
         return true;
     }
     if (!TraverseArray::remove($this->loadedRows, $path)) {
         return false;
     }
     // unsaved
     if (!in_array($path[0], $this->unsavedRows)) {
         $this->unsavedRows[] = $path[0];
     }
     return true;
     // current node pointer
     $currentNode =& $this->loadedRows;
 }