Skip to content

Commit

Permalink
Pass commands as string arrays for new daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jan 30, 2020
1 parent 28a1b75 commit e31c037
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 102 deletions.
1 change: 1 addition & 0 deletions bin/gt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use Gt\Cli\Argument\ArgumentList;
use Gt\Installer\Command\BuildCommand;
use Gt\Installer\Command\CreateCommand;
use Gt\Installer\Command\CronCommand;
use Gt\Installer\Command\MigrateCommand;
use Gt\Installer\Command\RunCommand;
use Gt\Installer\Command\ServeCommand;

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],

"require": {
"php": ">=7.2",
"php": ">=7.4",
"phpgt/cli": "*",
"phpgt/daemon": "*",
"phpgt/cron": "*",
Expand Down
98 changes: 48 additions & 50 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 27 additions & 44 deletions src/Command/AbstractWebEngineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,50 @@
abstract class AbstractWebEngineCommand extends Command {
public function executeScript(
ArgumentValueList $arguments = null,
string...$scriptsToRun
array...$scriptsToRun
):void {
$argString = "";
$stringArgumentArray = [];
//
// foreach($arguments as $arg) {
// $key = $arg->getKey();
//
// if($key !== Argument::USER_DATA) {
// $stringArgumentArray .= "--";
// $stringArgumentArray .= $key;
// }
//
// $value = $arg->get();
// if(!empty($value)) {
// $stringArgumentArray .= " ";
// $stringArgumentArray .= $value;
// }
// }

foreach($arguments as $arg) {
$key = $arg->getKey();
// var_dump($arguments);die();

if($key !== Argument::USER_DATA) {
$argString .= " ";
$argString .= "--";
$argString .= $key;
}
$processPool = new Pool();

$value = $arg->get();
if(!empty($value)) {
$argString .= " ";
$argString .= $value;
}
}
foreach($scriptsToRun as $scriptParts) {
/** @var string[] $scriptParts */

$processPool = new Pool();
$scriptName = $scriptParts[0];

foreach($scriptsToRun as $scriptName) {
$gtCommand = implode(DIRECTORY_SEPARATOR, [
$scriptParts[0] = implode(DIRECTORY_SEPARATOR, [
"vendor",
"bin",
$scriptName,
$scriptParts[0],
]);

$spacePos = strpos($gtCommand, " ");
$gtCommandWithoutArguments = $gtCommand;
if($spacePos > 0) {
$gtCommandWithoutArguments = substr(
$gtCommand,
0,
$spacePos
);
}
if(!file_exists($gtCommandWithoutArguments)) {
if(!file_exists($scriptParts[0])) {
$this->writeLine(
"The current directory is not a WebEngine application.",
Stream::ERROR
);
return;
}

if(!empty($argString)) {
$gtCommand .= $argString;
}

$friendlyScriptName = $gtCommandWithoutArguments;
$slashPos = strrpos($gtCommandWithoutArguments, "/");
if($slashPos > 0) {
$friendlyScriptName = substr(
$gtCommandWithoutArguments,
$slashPos + 1
);
}

$process = new Process($gtCommand);
$processPool->add($friendlyScriptName, $process);
$process = new Process(...$scriptParts);
$processPool->add($scriptName, $process);
}

$processPool->exec();
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

public function getName():string {
Expand Down
Loading

0 comments on commit e31c037

Please sign in to comment.