8000 Add forward compatibility layer for symfony/console >7.4 by chalasr · Pull Request #12445 · composer/composer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add forward compatibility layer for symfony/console >7.4 #12445

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

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions src/Composer/Console/Application.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public function doRun(InputInterface $input, OutputInterface $output): int
if ($this->has($command->getName())) {
$io->writeError('<warning>Plugin command '.$command->getName().' ('.get_class($command).') would override a Composer command and has been skipped</warning>');
} else {
$this->add($command);
// Compatibility layer for symfony/console <7.4
method_exists($this, 'addCommand') ? $this->addCommand($command) : $this->add($command);
}
}
} catch (NoSslException $e) {
Expand Down Expand Up @@ -380,7 +381,9 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow

$aliases = $composer['scripts-aliases'][$script] ?? [];

$this->add(new Command\ScriptAliasCommand($script, $description, $aliases));
$scriptAlias = new Command\ScriptAliasCommand($script, $description, $aliases);
// Compatibility layer for symfony/console <7.4
method_exists($this, 'addCommand') ? $this->addCommand($scriptAlias) : $this->add($scriptAlias);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Composer/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@ protected function doDispatch(Event $event)
}
$app->setAutoExit(false);
$cmd = new $className($event->getName());
$app->add($cmd);
if (method_exists($app, 'addCommand')) {
$app->addCommand($cmd);
} else {
// Compatibility layer for symfony/console <7.4
$app->add($cmd);
}
$app->setDefaultCommand((string) $cmd->getName(), true);
try {
$args = implode(' ', array_map(static function ($arg) { return ProcessExecutor::escape($arg); }, $additionalArgs));
Expand Down
6 changes: 4 additions & 2 deletions tests/Composer/Test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function testDevWarningSuppressedForSelfUpdate(): void
}

$application = new Application;
$application->add(new \Composer\Command\SelfUpdateCommand);
// Compatibility layer for symfony/console <7.4
method_exists($application, 'addCommand') ? $application->addCommand(new \Composer\Command\SelfUpdateCommand) : $application->add(new \Composer\Command\SelfUpdateCommand);

if (!defined('COMPOSER_DEV_WARNING_TIME')) {
define('COMPOSER_DEV_WARNING_TIME', time() - 1);
Expand All @@ -82,7 +83,8 @@ public function testDevWarningSuppressedForSelfUpdate(): void
public function testProcessIsolationWorksMultipleTimes(): void
{
$application = new Application;
$application->add(new \Composer\Command\AboutCommand);
// Compatibility layer for symfony/console <7.4
method_exists($application, 'addCommand') ? $application->addCommand(new \Composer\Command\AboutCommand) : $application->add(new \Composer\Command\AboutCommand);
self::assertSame(0, $application->doRun(new ArrayInput(['command' => 'about']), new BufferedOutput()));
self::assertSame(0, $application->doRun(new ArrayInput(['command' => 'about']), new BufferedOutput()));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Composer/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private function doTestIntegration(string $file, string $message, ?string $condi

return $installer->run();
});
$application->add($install);
method_exists($application, 'addCommand') ? $application->addCommand($install) : $application->add($install);

$update = new Command('update');
$update->addOption('ignore-platform-reqs', null, InputOption::VALUE_NONE);
Expand Down Expand Up @@ -420,7 +420,7 @@ private function doTestIntegration(string $file, string $message, ?string $condi

return $installer->run();
});
$application->add($update);
method_exists($application, 'addCommand') ? $application->addCommand($update) : $application->add($update);

if (!Preg::isMatch('{^(install|update)\b}', $run)) {
throw new \UnexpectedValueException('The run command only supports install and update');
Expand Down
Loading
0