From 0e0ae9ff09adb1943225555eb2798b5727b7dac9 Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Thu, 12 Aug 2021 14:44:24 +0200 Subject: [PATCH 1/2] Workaround for constructor signature change in Symfony/Process --- bin/composer-script/CreateProjectScript.php | 2 + bin/composer-script/PostInstallScript.php | 4 +- bin/composer-script/PostUpdateScript.php | 2 + .../PrePackageUninstallScript.php | 2 + bin/composer-script/ProjectEventHandler.php | 9 ++-- bin/composer-script/Script.php | 46 +++++++++++++++++-- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/bin/composer-script/CreateProjectScript.php b/bin/composer-script/CreateProjectScript.php index 070c0d9c8..ccdd5516b 100644 --- a/bin/composer-script/CreateProjectScript.php +++ b/bin/composer-script/CreateProjectScript.php @@ -1,5 +1,7 @@ create(); @@ -30,9 +35,42 @@ protected static function getProjectFolder(Event $event): string /** * Execute a command in the CLI, as a separate process. */ - protected static function run(string $command): void + protected static function run(string $command): int { - $process = new Process($command); - $process->run(); + // Depending on the context, we're using either Symfony/Process 2.8.52 (bundled with composer 2.1.x) + // or Symfony/Process 5.3.x (if we're using our own). The signature of the Constructor changed + // from: `public function __construct(string $commandline, …)` + // to: `public function __construct(array $command, …)` + // We'll have to attempt one, and otherwise fall back to the other. + + try { + $process = new Process([$command]); + } catch (\TypeError $e) { + $process = new Process($command); + } + + return $process->run(); + } + + /** + * Create SymfonyStyle object. Taken from Symplify (which we might not + * have at our disposal inside a 'project' installation) + */ + public static function createSymfonyStyle(): SymfonyStyle + { + // to prevent missing argv indexes + if (! isset($_SERVER['argv'])) { + $_SERVER['argv'] = []; + } + + $argvInput = new ArgvInput(); + $consoleOutput = new ConsoleOutput(); + + // --debug is called + if ($argvInput->hasParameterOption('--debug')) { + $consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG); + } + + return new SymfonyStyle($argvInput, $consoleOutput); } } From 695eb184062cb8652fead53701c1c458b3b6f78b Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Thu, 12 Aug 2021 14:51:55 +0200 Subject: [PATCH 2/2] Update Script.php --- bin/composer-script/Script.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/composer-script/Script.php b/bin/composer-script/Script.php index b8e717feb..0b4cc8608 100644 --- a/bin/composer-script/Script.php +++ b/bin/composer-script/Script.php @@ -44,9 +44,9 @@ protected static function run(string $command): int // We'll have to attempt one, and otherwise fall back to the other. try { - $process = new Process([$command]); - } catch (\TypeError $e) { $process = new Process($command); + } catch (\TypeError $e) { + $process = new Process([$command]); } return $process->run();