Multiple fixes
* PDO shell improvements: .query command, -r and --db on command line to read commands from file or preselect database. * Updated build scripts and readme
This commit is contained in:
		@@ -47,47 +47,6 @@ class Environment
 | 
			
		||||
        return $runner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    public function runScript(string $name, array $args, InputInterface $input, OutputInterface $output)
 | 
			
		||||
    {
 | 
			
		||||
        $script = $this->config['scripts'][$name]??$name;
 | 
			
		||||
        
 | 
			
		||||
        if (is_string($script)) {
 | 
			
		||||
            $this->execScript($script, $args, $output);
 | 
			
		||||
        } elseif (is_array($script)) {
 | 
			
		||||
            foreach ($script as $row) {
 | 
			
		||||
                $a = str_getcsv($row, ' ', "'");
 | 
			
		||||
                $c = array_shift($a);
 | 
			
		||||
                if (str_starts_with($c, '@')) {
 | 
			
		||||
                    $c = ($this->config['scripts'][substr($c,1)])??$c;
 | 
			
		||||
                    $this->runScript($c, $a, $input, $output);
 | 
			
		||||
                } else {
 | 
			
		||||
                    $this->execScript($c, $a, $output);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function execScript(string $script, array $args, OutputInterface $output)
 | 
			
		||||
    {
 | 
			
		||||
            // call script directly
 | 
			
		||||
            if (str_ends_with($script, '.php')) {
 | 
			
		||||
                $GLOBALS['args'] = $args;
 | 
			
		||||
                $GLOBALS['output'] = $output;
 | 
			
		||||
                $base = $this->getProjectDirectory();
 | 
			
		||||
                if (!file_exists($base ."/". $script)) {
 | 
			
		||||
                    fprintf(STDERR, "error: Could not find script file %s\n", $base."/".$script);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                //echo "# ".$base."/".$script."\n";
 | 
			
		||||
                include $base . "/" . $script;
 | 
			
		||||
            } else {
 | 
			
		||||
                //echo "$ {$script}\n";
 | 
			
		||||
                passthru($script);
 | 
			
		||||
            }
 | 
			
		||||
    }
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    public function loadEnvironment()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->loaded) {
 | 
			
		||||
@@ -135,7 +94,7 @@ class Environment
 | 
			
		||||
                try {
 | 
			
		||||
                    include_once($item);
 | 
			
		||||
                } catch (\Throwable $t) {
 | 
			
		||||
                    fprintf(STDERR, "error: Error preloading %s: %s in %s on line %d\n", $item,  $t->getMessage(), $t->getFile(), $t->getLine());
 | 
			
		||||
                    fprintf(STDERR, "warning: Error preloading %s: %s in %s on line %d\n", $item,  $t->getMessage(), $t->getFile(), $t->getLine());
 | 
			
		||||
                    //$this->logger->error("Error preloading {$item}: {$t->getMessage()} in {$t->getFile()} on line {$t->getLine()}");
 | 
			
		||||
                }
 | 
			
		||||
            } elseif (is_dir($item) && file_exists($item."/sparkplug.php")) {
 | 
			
		||||
@@ -143,7 +102,7 @@ class Environment
 | 
			
		||||
                try {
 | 
			
		||||
                    include_once($item."/sparkplug.php");
 | 
			
		||||
                } catch (\Throwable $t) {
 | 
			
		||||
                    fprintf(STDERR, "error: Error preloading plugin %s: %s in %s on line %d\n", $item,  $t->getMessage(), $t->getFile(), $t->getLine());
 | 
			
		||||
                    fprintf(STDERR, "warning: Error preloading plugin %s: %s in %s on line %d\n", $item,  $t->getMessage(), $t->getFile(), $t->getLine());
 | 
			
		||||
                    //$this->logger->error("Error preloading plugin {$item}: {$t->getMessage()} in {$t->getFile()} on line {$t->getLine()}");
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
@@ -174,9 +133,9 @@ class Environment
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function createFromDirectory(string|null $directory=null, bool $parents=false): Environment
 | 
			
		||||
    public static function createFromDirectory(string|null $directory=null, bool $parents=false): ?Environment
 | 
			
		||||
    {
 | 
			
		||||
        $directory = $directory ?? getcwd();
 | 
			
		||||
        $directory = realpath($directory) ?? getcwd();
 | 
			
		||||
        
 | 
			
		||||
        if ($parents) {
 | 
			
		||||
            $check = $directory;
 | 
			
		||||
@@ -190,7 +149,7 @@ class Environment
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $candidates = [ $directory . "/.spark.json", $directory . "/.spark/spark.json" ];
 | 
			
		||||
        $candidates = [ $directory . "/.spark.json", $directory . "/spark.json", $directory . "/.spark/spark.json" ];
 | 
			
		||||
        $config = [];
 | 
			
		||||
        while ($candidate = array_shift($candidates)) {
 | 
			
		||||
            if (!file_exists($candidate)) { continue; }
 | 
			
		||||
@@ -205,6 +164,9 @@ class Environment
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$config) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        $env = new Environment($config);
 | 
			
		||||
 | 
			
		||||
        return $env;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user