Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 5 compatibility: new Symfony\Component\Process\Process() only accepts an array #48

Merged
merged 5 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/Parallelization.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,17 @@ function () use ($input) {
sprintf('The bin/console file could not be found at %s', getcwd()))
;

$commandTemplate = implode(
' ',
array_merge(
array_filter([
self::detectPhpExecutable(),
$consolePath,
$this->getName(),
implode(' ', array_slice($input->getArguments(), 1)),
'--child',
]),
$this->serializeInputOptions($input, ['child', 'processes'])
)
$commandTemplate = array_merge(
array_filter([
self::detectPhpExecutable(),
$consolePath,
$this->getName(),
implode(' ', array_slice($input->getArguments(), 1)),
'--child',
]),
$this->serializeInputOptions($input, ['child', 'processes'])
);

$terminalWidth = (new Terminal())->getWidth();

$processLauncher = new ProcessLauncher(
Expand Down Expand Up @@ -517,13 +515,13 @@ private function serializeInputOptions(InputInterface $input, array $blackListPa

$optionString = '';
if (!$option->acceptValue()) {
$optionString .= ' --'.$name;
$optionString .= '--'.$name;
} elseif ($option->isArray()) {
foreach ($value as $arrayValue) {
$optionString .= ' --'.$name.'='.$arrayValue;
$optionString .= '--'.$name.'='.$arrayValue;
}
} else {
$optionString .= ' --'.$name.'='.$value;
$optionString .= '--'.$name.'='.$value;
}

$preparedOptionList[] = $optionString;
Expand Down
11 changes: 8 additions & 3 deletions src/ProcessLauncher.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
*/
class ProcessLauncher
{
/**
* @var array
*/
private $command;

private $workingDirectory;
Expand All @@ -49,7 +52,7 @@ class ProcessLauncher
private $runningProcesses = [];

public function __construct(
string $command,
array $command,
string $workingDirectory,
array $environmentVariables,
int $processLimit,
Expand Down Expand Up @@ -137,10 +140,12 @@ private function startProcess(InputStream $inputStream): void
);

$process->setInput($inputStream);
$process->inheritEnvironmentVariables(true);
if(method_exists($process, 'inheritEnvironmentVariables')) {
$process->inheritEnvironmentVariables(true);
}
$process->start($this->callback);

$this->logger->debug('Command started: '.$this->command);
$this->logger->debug('Command started: '. implode(' ', $this->command));

$this->runningProcesses[] = $process;
}
Expand Down