Skip to content

Commit e31c037

Browse files
author
Greg Bowler
committed
Pass commands as string arrays for new daemon
1 parent 28a1b75 commit e31c037

9 files changed

Lines changed: 84 additions & 102 deletions

File tree

bin/gt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use Gt\Cli\Argument\ArgumentList;
66
use Gt\Installer\Command\BuildCommand;
77
use Gt\Installer\Command\CreateCommand;
88
use Gt\Installer\Command\CronCommand;
9+
use Gt\Installer\Command\MigrateCommand;
910
use Gt\Installer\Command\RunCommand;
1011
use Gt\Installer\Command\ServeCommand;
1112

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
],
77

88
"require": {
9-
"php": ">=7.2",
9+
"php": ">=7.4",
1010
"phpgt/cli": "*",
1111
"phpgt/daemon": "*",
1212
"phpgt/cron": "*",

composer.lock

Lines changed: 48 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Command/AbstractWebEngineCommand.php

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,50 @@
1111
abstract class AbstractWebEngineCommand extends Command {
1212
public function executeScript(
1313
ArgumentValueList $arguments = null,
14-
string...$scriptsToRun
14+
array...$scriptsToRun
1515
):void {
16-
$argString = "";
16+
$stringArgumentArray = [];
17+
//
18+
// foreach($arguments as $arg) {
19+
// $key = $arg->getKey();
20+
//
21+
// if($key !== Argument::USER_DATA) {
22+
// $stringArgumentArray .= "--";
23+
// $stringArgumentArray .= $key;
24+
// }
25+
//
26+
// $value = $arg->get();
27+
// if(!empty($value)) {
28+
// $stringArgumentArray .= " ";
29+
// $stringArgumentArray .= $value;
30+
// }
31+
// }
1732

18-
foreach($arguments as $arg) {
19-
$key = $arg->getKey();
33+
// var_dump($arguments);die();
2034

21-
if($key !== Argument::USER_DATA) {
22-
$argString .= " ";
23-
$argString .= "--";
24-
$argString .= $key;
25-
}
35+
$processPool = new Pool();
2636

27-
$value = $arg->get();
28-
if(!empty($value)) {
29-
$argString .= " ";
30-
$argString .= $value;
31-
}
32-
}
37+
foreach($scriptsToRun as $scriptParts) {
38+
/** @var string[] $scriptParts */
3339

34-
$processPool = new Pool();
40+
$scriptName = $scriptParts[0];
3541

36-
foreach($scriptsToRun as $scriptName) {
37-
$gtCommand = implode(DIRECTORY_SEPARATOR, [
42+
$scriptParts[0] = implode(DIRECTORY_SEPARATOR, [
3843
"vendor",
3944
"bin",
40-
$scriptName,
45+
$scriptParts[0],
4146
]);
4247

43-
$spacePos = strpos($gtCommand, " ");
44-
$gtCommandWithoutArguments = $gtCommand;
45-
if($spacePos > 0) {
46-
$gtCommandWithoutArguments = substr(
47-
$gtCommand,
48-
0,
49-
$spacePos
50-
);
51-
}
52-
if(!file_exists($gtCommandWithoutArguments)) {
48+
if(!file_exists($scriptParts[0])) {
5349
$this->writeLine(
5450
"The current directory is not a WebEngine application.",
5551
Stream::ERROR
5652
);
5753
return;
5854
}
5955

60-
if(!empty($argString)) {
61-
$gtCommand .= $argString;
62-
}
63-
64-
$friendlyScriptName = $gtCommandWithoutArguments;
65-
$slashPos = strrpos($gtCommandWithoutArguments, "/");
66-
if($slashPos > 0) {
67-
$friendlyScriptName = substr(
68-
$gtCommandWithoutArguments,
69-
$slashPos + 1
70-
);
71-
}
72-
73-
$process = new Process($gtCommand);
74-
$processPool->add($friendlyScriptName, $process);
56+
$process = new Process(...$scriptParts);
57+
$processPool->add($scriptName, $process);
7558
}
7659

7760
$processPool->exec();

src/Command/BuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class BuildCommand extends AbstractWebEngineCommand {
99
public function run(ArgumentValueList $arguments = null):void {
10-
$this->executeScript($arguments, "build");
10+
$this->executeScript($arguments, ["build"]);
1111
}
1212

1313
public function getName():string {

0 commit comments

Comments
 (0)