Improved runtime and script classes
This commit is contained in:
parent
5af63f771a
commit
c3e97ea4b1
@ -35,6 +35,7 @@
|
||||
"symfony/finder": "^6.0",
|
||||
"symfony/process": "^6.0",
|
||||
"psr/log": "^3.0",
|
||||
"symfony/var-dumper": "^6.0"
|
||||
"symfony/var-dumper": "^6.0",
|
||||
"symfony/yaml": "^6.0"
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,13 @@ abstract class SparkPlug
|
||||
return SparkApplication::$instance->getPluginManager()->getPlugin($name);
|
||||
}
|
||||
|
||||
function get_resource(string $name) {
|
||||
function getResource(string $name)
|
||||
{
|
||||
return SparkApplication::$instance->getResourceManager()->getNamedResource($name);
|
||||
}
|
||||
|
||||
function read_config($file=null) {
|
||||
function readConfig($file=null)
|
||||
{
|
||||
if (!$file) return;
|
||||
$abs = get_environment()->getConfigDirectory() . "/" . $file;
|
||||
if (!file_exists($abs)) {
|
||||
@ -29,5 +31,6 @@ abstract class SparkPlug
|
||||
{
|
||||
return SparkApplication::$instance->getEnvironment()->getProjectDirectory();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -22,14 +22,21 @@ class RunCommand extends Command
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$env = $this->getEnvironment();
|
||||
$args = $input->getArgument('args');
|
||||
|
||||
if ($input->getOption("list")) {
|
||||
$output->writeln($env->getDefinedScripts());
|
||||
if ($input->getOption("list") || empty($input->getArgument("script"))) {
|
||||
$scripts = $env->getDefinedScripts();
|
||||
if (count($scripts) > 0) {
|
||||
$output->writeln("<options=bold>Defined scripts:</>");
|
||||
$output->writeln("- ".join("\n- ",$scripts));
|
||||
} else {
|
||||
$output->writeln("No scripts defined.");
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
} elseif ($script = $input->getArgument('script')) {
|
||||
$env->runScript($script, $input->getArgument('args'), $input, $output);
|
||||
$env->runScript($script, $args, $input, $output);
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,26 @@ class Environment
|
||||
|
||||
public function runScript(string $name, array $args, InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$script = $this->config['scripts'][$name];
|
||||
$script = $this->config['scripts'][$name]??$name;
|
||||
|
||||
if (is_string($script)) {
|
||||
$this->execScript($script, $args);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function execScript(string $script, array $args)
|
||||
{
|
||||
// call script directly
|
||||
if (str_ends_with($script, '.php')) {
|
||||
$GLOBALS['args'] = $args;
|
||||
@ -50,11 +67,12 @@ class Environment
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user