/** @test */
 public function it_has_nodes()
 {
     $array = ["foo" => ["bar" => 5], "asd" => 2];
     $this->assertTrue(TraverseArray::has($array, "foo.bar"));
     $this->assertTrue(TraverseArray::has($array, "foo"));
     $this->assertFalse(TraverseArray::has($array, "baz"));
 }
 /**
  * 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.");
     }
 }
Exemple #3
0
 public function hasNode(Path $path)
 {
     return TraverseArray::has($this->rootNode, $path, true, function ($mounterClass, $relativePath, $path) {
         return $this->router->query($mounterClass)->hasNode($relativePath);
     });
 }