From 849bc51ce7318f9c9b4e020f2dcbaf4fd68b064a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 7 Apr 2022 15:16:13 +0200 Subject: [PATCH] Fix ProcessExecutor bootstrapping, fixes #10703 --- src/Composer/Command/CreateProjectCommand.php | 2 +- src/Composer/Command/DiagnoseCommand.php | 4 +++- src/Composer/Command/StatusCommand.php | 2 +- src/Composer/Downloader/FileDownloader.php | 2 +- src/Composer/Downloader/VcsDownloader.php | 4 ++-- src/Composer/EventDispatcher/EventDispatcher.php | 2 +- src/Composer/Package/Locker.php | 2 +- src/Composer/Platform/HhvmDetector.php | 2 +- src/Composer/Repository/RepositoryManager.php | 2 +- src/Composer/Repository/VcsRepository.php | 2 +- 10 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index bda43c5fab2b..1e98f836df96 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -235,7 +235,7 @@ public function installProject(IOInterface $io, Config $config, InputInterface $ } } - $process = new ProcessExecutor($io); + $process = $composer->getLoop()->getProcessExecutor(); $fs = new Filesystem($process); // dispatch event diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index 93ef3c22ae5e..cb49c2d24201 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -80,6 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->write('Checking composer.json: ', false); $this->outputResult($this->checkComposerSchema()); + $this->process = $composer->getLoop()->getProcessExecutor() ?? new ProcessExecutor($io); + } else { + $this->process = new ProcessExecutor($io); } if ($composer) { @@ -92,7 +95,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $config->prohibitUrlByConfig('http://repo.packagist.org', new NullIO); $this->httpDownloader = Factory::createHttpDownloader($io, $config); - $this->process = new ProcessExecutor($io); $io->write('Checking platform settings: ', false); $this->outputResult($this->checkPlatform()); diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 2a13880398ed..c749294d97a0 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -96,7 +96,7 @@ private function doExecute(InputInterface $input): int $vcsVersionChanges = array(); $parser = new VersionParser; - $guesser = new VersionGuesser($composer->getConfig(), new ProcessExecutor($io), $parser); + $guesser = new VersionGuesser($composer->getConfig(), $composer->getLoop()->getProcessExecutor() ?? new ProcessExecutor($io), $parser); $dumper = new ArrayDumper; // list packages diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 2fb583afd6e2..38aff1a4dda3 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -89,7 +89,7 @@ public function __construct(IOInterface $io, Config $config, HttpDownloader $htt $this->eventDispatcher = $eventDispatcher; $this->httpDownloader = $httpDownloader; $this->cache = $cache; - $this->process = $process ?: new ProcessExecutor($io); + $this->process = $process ?? new ProcessExecutor($io); $this->filesystem = $filesystem ?: new Filesystem($this->process); if ($this->cache && $this->cache->gcIsNecessary()) { diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index b4dfdfe0ac49..eb5336c70296 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -45,8 +45,8 @@ public function __construct(IOInterface $io, Config $config, ProcessExecutor $pr { $this->io = $io; $this->config = $config; - $this->process = $process ?: new ProcessExecutor($io); - $this->filesystem = $fs ?: new Filesystem($this->process); + $this->process = $process ?? new ProcessExecutor($io); + $this->filesystem = $fs ?? new Filesystem($this->process); } /** diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index 1fcbb89af3b2..d19245ad37c5 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -71,7 +71,7 @@ public function __construct(PartialComposer $composer, IOInterface $io, ProcessE { $this->composer = $composer; $this->io = $io; - $this->process = $process ?: new ProcessExecutor($io); + $this->process = $process ?? new ProcessExecutor($io); $this->eventStack = array(); } diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index bb780bb54fef..b9fd396df050 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -68,7 +68,7 @@ public function __construct(IOInterface $io, JsonFile $lockFile, InstallationMan $this->contentHash = self::getContentHash($composerFileContents); $this->loader = new ArrayLoader(null, true); $this->dumper = new ArrayDumper(); - $this->process = $process ?: new ProcessExecutor($io); + $this->process = $process ?? new ProcessExecutor($io); } /** diff --git a/src/Composer/Platform/HhvmDetector.php b/src/Composer/Platform/HhvmDetector.php index f6c5829b6b4d..29e9dac2fbba 100644 --- a/src/Composer/Platform/HhvmDetector.php +++ b/src/Composer/Platform/HhvmDetector.php @@ -54,7 +54,7 @@ public function getVersion(): ?string $this->executableFinder = $this->executableFinder ?: new ExecutableFinder(); $hhvmPath = $this->executableFinder->find('hhvm'); if ($hhvmPath !== null) { - $this->processExecutor = $this->processExecutor ?: new ProcessExecutor(); + $this->processExecutor = $this->processExecutor ?? new ProcessExecutor(); $exitCode = $this->processExecutor->execute( ProcessExecutor::escape($hhvmPath). ' --php -d hhvm.jit=0 -r "echo HHVM_VERSION;" 2>/dev/null', diff --git a/src/Composer/Repository/RepositoryManager.php b/src/Composer/Repository/RepositoryManager.php index c09fe1421008..d1b516cb4612 100644 --- a/src/Composer/Repository/RepositoryManager.php +++ b/src/Composer/Repository/RepositoryManager.php @@ -51,7 +51,7 @@ public function __construct(IOInterface $io, Config $config, HttpDownloader $htt $this->config = $config; $this->httpDownloader = $httpDownloader; $this->eventDispatcher = $eventDispatcher; - $this->process = $process ?: new ProcessExecutor($io); + $this->process = $process ?? new ProcessExecutor($io); } /** diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 41587f5b5d33..95828c1e24b8 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -99,7 +99,7 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config, $this->repoConfig = $repoConfig; $this->versionCache = $versionCache; $this->httpDownloader = $httpDownloader; - $this->processExecutor = $process ?: new ProcessExecutor($io); + $this->processExecutor = $process ?? new ProcessExecutor($io); } public function getRepoName()