Skip to content

Commit

Permalink
Use argseparator (--) also for PHP CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jun 21, 2017
1 parent d3ccd57 commit ba4e101
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/Process/ChannelledProcess.php
Expand Up @@ -28,12 +28,28 @@ class ChannelledProcess implements ProcessContext, Strand {
* @param mixed[] $env Array of environment variables.
*/
public function __construct(string $path, string $cwd = "", array $env = []) {
$options = "-d html_errors=0 -d display_errors=0 -d log_errors=1";
$binary = \PHP_SAPI === "phpdbg" ? \PHP_BINARY . " -b -qrr $options --" : \PHP_BINARY . " " . $options;
$command = $binary . " " . \escapeshellarg($path);
$options = [
"html_errors" => "0",
"display_errors" => "0",
"log_errors" => "1",
];

$options = (\PHP_SAPI === "phpdbg" ? " -b -qrr " : " ") . $this->formatOptions($options) . " -- ";
$command = \PHP_BINARY . $options . \escapeshellarg($path);

$this->process = new Process($command, $cwd, $env);
}

private function formatOptions(array $options) {
$result = [];

foreach ($options as $option => $value) {
$result[] = \sprintf("-d %s=%s", $option, $value);
}

return \implode(" ", $result);
}

/**
* Resets process values.
*/
Expand All @@ -47,7 +63,7 @@ public function __clone() {
*/
public function start() {
$this->process->start();
$this->channel = new ChannelledStream($this->process->getStdOut(), $this->process->getStdIn());
$this->channel = new ChannelledStream($this->process->getStdout(), $this->process->getStdin());
}

/**
Expand Down

0 comments on commit ba4e101

Please sign in to comment.