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; } }
/** * Remove a node * @return bool Returns true if node node has been removed, false if it doesn't exist already */ public static function remove(&$array, $path, $handleMounting = false, $onMountHit = null) { $path = new Path($path); if ($path->root()) { throw new MyceliumException("Cannot remove entire array."); } $node =& $array; for ($i = 0; $i < $path->length(); $i++) { // is the current node a mounted node? if ($handleMounting && array_key_exists("@mount", $node)) { // callback(mounterClass, relativePath, pathToTheMountNode) $onMountHit($node["@mount"], $path->cut($i), $path->clamp($i)); } // does the next node exist? if (!array_key_exists($path[$i], $node)) { return false; } // last path segment? if ($i == $path->length() - 1) { // remove the node unset($node[$path[$i]]); return true; } // is the next node an array? if (!is_array($node[$path[$i]])) { return false; } // continue deeper $node =& $node[$path[$i]]; } }