Exemplo 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);
 }
Exemplo n.º 2
0
 public function getNode(Path $path, $default)
 {
     // show all gds rows if no path
     if ($path->root()) {
         // load all rows
         $keys = $this->queryGdsTable()->select("key")->get();
         foreach ($keys as $k) {
             try {
                 $this->getRow($k->key);
             } catch (TableRowNotFoundException $e) {
                 // just ignore this exception, this happens if a row technically exists, but is gonna be deleted on save
             }
         }
         return $this->loadedRows;
     }
     try {
         $row =& $this->getRow($path[0]);
         return TraverseArray::get($row, $path->cut(1), $default);
     } catch (TableRowNotFoundException $e) {
         return $default;
     }
 }
Exemplo 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.");
     }
 }
Exemplo n.º 4
0
 public function getNode(Path $path, $default)
 {
     return TraverseArray::get($this->rootNode, $path, $default, true, function ($mounterClass, $relativePath, $default, $path) {
         return $this->router->query($mounterClass)->getNode($relativePath, $default);
     });
 }