From 2365b7842b2408aa11e471bc79448db867c1d011 Mon Sep 17 00:00:00 2001 From: Justin Beaty <51970393+justinbeaty@users.noreply.github.com> Date: Tue, 10 Dec 2024 07:12:08 -0800 Subject: [PATCH] Fix bug when plugin defines multiple PluginInterface classes (#12226) * Fix bug when plugin defines multiple PluginInterface classes * PHP 5.3 array syntax --- src/Composer/Plugin/PluginManager.php | 37 +++++++++++++++------------ 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index 29cca6a19..96ae83fdd 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -52,7 +52,7 @@ class PluginManager /** @var array */ protected $plugins = array(); - /** @var array */ + /** @var array> */ protected $registeredPlugins = array(); /** @@ -210,6 +210,7 @@ class PluginManager if (isset($this->registeredPlugins[$package->getName()])) { return; } + $this->registeredPlugins[$package->getName()] = array(); $extra = $package->getExtra(); if (empty($extra['class'])) { @@ -295,14 +296,14 @@ class PluginManager $this->io->writeError('Loading "'.$package->getName() . '" '.($isGlobalPlugin ? '(installed globally) ' : '').'which is a legacy composer-installer built for Composer 1.x, it is likely to cause issues as you are running Composer 2.x.'); $installer = new $class($this->io, $this->composer); $this->composer->getInstallationManager()->addInstaller($installer); - $this->registeredPlugins[$package->getName()] = $installer; + $this->registeredPlugins[$package->getName()][] = $installer; } elseif (class_exists($class)) { if (!is_a($class, 'Composer\Plugin\PluginInterface', true)) { throw new \RuntimeException('Could not activate plugin "'.$package->getName().'" as "'.$class.'" does not implement Composer\Plugin\PluginInterface'); } $plugin = new $class(); $this->addPlugin($plugin, $isGlobalPlugin, $package); - $this->registeredPlugins[$package->getName()] = $plugin; + $this->registeredPlugins[$package->getName()][] = $plugin; } elseif ($failOnMissingClasses) { throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class); } @@ -327,13 +328,15 @@ class PluginManager return; } - $plugin = $this->registeredPlugins[$package->getName()]; - unset($this->registeredPlugins[$package->getName()]); - if ($plugin instanceof InstallerInterface) { - $this->composer->getInstallationManager()->removeInstaller($plugin); - } else { - $this->removePlugin($plugin); + $plugins = $this->registeredPlugins[$package->getName()]; + foreach ($plugins as $plugin) { + if ($plugin instanceof InstallerInterface) { + $this->composer->getInstallationManager()->removeInstaller($plugin); + } else { + $this->removePlugin($plugin); + } } + unset($this->registeredPlugins[$package->getName()]); } /** @@ -354,14 +357,16 @@ class PluginManager return; } - $plugin = $this->registeredPlugins[$package->getName()]; - if ($plugin instanceof InstallerInterface) { - $this->deactivatePackage($package); - } else { - unset($this->registeredPlugins[$package->getName()]); - $this->removePlugin($plugin); - $this->uninstallPlugin($plugin); + $plugins = $this->registeredPlugins[$package->getName()]; + foreach ($plugins as $plugin) { + if ($plugin instanceof InstallerInterface) { + $this->composer->getInstallationManager()->removeInstaller($plugin); + } else { + $this->removePlugin($plugin); + $this->uninstallPlugin($plugin); + } } + unset($this->registeredPlugins[$package->getName()]); } /**