function command(&$path, $cmds) { array_shift($cmds); $c = $cmds[0]; $full = implode(' ', $cmds); switch ($c) { case ".": break; case "..": array_pop($path); break; case "/": $path = []; break; case in_array($c, $this->tables) && count(explode('/', $full)) < 2: if (count($path) == 0) { array_push($path, $c); } break; default: $c = implode(' ', $cmds); $parts = explode('/', $c); $savedpath = $path; if (\CliWrapper\CliHelper::isInteger($c)) { $c = "id={$c}"; } if (count($parts) > 1) { foreach ($parts as $part) { $path[] = trim($part); } } else { if (count($path) > 0) { array_push($path, $c); } else { echo "Table '{$c}' not found\n"; } } if ($this->count($path) == -1) { $path = $savedpath; } } return $this->count($path); }
function command(&$path, $cmds) { $id = ""; if (count($cmds) == 3) { $class = $cmds[1]; $id = $cmds[2]; } if (count($cmds) == 2) { $id = $cmds[1]; if (count($path) > 0) { $class = $path[0]; } else { return; } } if (count($cmds) == 1) { if (count($path) > 0) { $class = $path[0]; } else { return; } } $cols = $this->colums[$class]; if ($id != "") { $res = $this->con->query("SELECT * FROM `{$class}` WHERE id = {$id}")->fetch(\PDO::FETCH_ASSOC); } else { $res = $this->con->query($this->buildQuery("SELECT * ", $path))->fetch(\PDO::FETCH_ASSOC); } if ($res != "") { $items = []; } foreach ($cols as $key) { $val = $res[$key]; if (is_array($val)) { $val = "[" . implode(',', $val) . "]"; } $items[] = ['attribute' => $key . ': ', 'value' => $val]; } \CliWrapper\CliHelper::prettyPrint($items, '.', 10, [STR_PAD_RIGHT, STR_PAD_LEFT]); }
function command(&$path, $cmds) { $results = $this->con->query($this->buildQuery("SELECT * ", $path)); array_shift($cmds); if (count($path > 0)) { $keys = $cmds; if (count($keys) == 0) { $keys = array_slice($this->colums[$path[0]], 0, 5); } $i = 0; $items = []; while ($r = $results->fetch(\PDO::FETCH_ASSOC)) { $i++; reset($keys); $row = []; foreach ($keys as $key) { if ($key != "") { try { $val = $r[$key]; if (is_array($val)) { $out = '["' . implode('","', $val) . '"]'; } else { if (is_numeric($val)) { $out = $val; } else { $out = '"' . $val . '"'; } } $row[$key] = $out; } catch (Exception $e) { echo "field does not exist"; } } } $items[] = $row; } \CliWrapper\CliHelper::prettyPrint($items, ' '); } }