diff --git a/src/Parallelization.php b/src/Parallelization.php index 65c90d1..e973911 100644 --- a/src/Parallelization.php +++ b/src/Parallelization.php @@ -37,6 +37,7 @@ use Symfony\Component\DependencyInjection\ResettableContainerInterface; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Contracts\Service\ResetInterface; +use Symfony\Component\Process\Process; use Throwable; use function trim; use Webmozart\Assert\Assert; @@ -359,23 +360,25 @@ 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(); + // @TODO: can be removed once ProcessLauncher accepts command arrays + $tempProcess = new Process($commandTemplate); + $commandString = $tempProcess->getCommandLine(); + $processLauncher = new ProcessLauncher( - $commandTemplate, + $commandString, self::getWorkingDirectory($this->getContainer()), $this->getEnvironmentVariables($this->getContainer()), $numberOfProcesses, @@ -517,13 +520,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; diff --git a/src/ProcessLauncher.php b/src/ProcessLauncher.php index 82eef3e..ddd22bc 100644 --- a/src/ProcessLauncher.php +++ b/src/ProcessLauncher.php @@ -49,7 +49,7 @@ class ProcessLauncher private $runningProcesses = []; public function __construct( - string $command, + string $command, // @TODO change to array for 2.0 string $workingDirectory, array $environmentVariables, int $processLimit, @@ -128,16 +128,26 @@ public function run(array $items): void */ private function startProcess(InputStream $inputStream): void { - $process = new Process( + $arguments = [ $this->command, $this->workingDirectory, $this->environmentVariables, null, null - ); + ]; + + if(method_exists(Process::class, 'fromShellCommandline')) { + // Symfony >= 4.2 workaround as Symfony 5 requires `Process` to be initiated with an array + // @TODO: can be removed once $this->command was changed to an array + $process = Process::fromShellCommandline(...$arguments); + } else { + $process = new Process(...$arguments); + } $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);