Fix bug when plugin defines multiple PluginInterface classes (#12226)
parent
eefa012204
commit
5cb9733588
|
@ -55,7 +55,7 @@ class PluginManager
|
||||||
|
|
||||||
/** @var array<PluginInterface> */
|
/** @var array<PluginInterface> */
|
||||||
protected $plugins = [];
|
protected $plugins = [];
|
||||||
/** @var array<string, PluginInterface|InstallerInterface> */
|
/** @var array<string, array<PluginInterface|InstallerInterface>> */
|
||||||
protected $registeredPlugins = [];
|
protected $registeredPlugins = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,6 +201,7 @@ class PluginManager
|
||||||
if (isset($this->registeredPlugins[$package->getName()])) {
|
if (isset($this->registeredPlugins[$package->getName()])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$this->registeredPlugins[$package->getName()] = [];
|
||||||
|
|
||||||
$extra = $package->getExtra();
|
$extra = $package->getExtra();
|
||||||
if (empty($extra['class'])) {
|
if (empty($extra['class'])) {
|
||||||
|
@ -289,14 +290,14 @@ class PluginManager
|
||||||
$this->io->writeError('<warning>Loading "'.$package->getName() . '" '.($isGlobalPlugin || $this->runningInGlobalDir ? '(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.</warning>');
|
$this->io->writeError('<warning>Loading "'.$package->getName() . '" '.($isGlobalPlugin || $this->runningInGlobalDir ? '(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.</warning>');
|
||||||
$installer = new $class($this->io, $this->composer);
|
$installer = new $class($this->io, $this->composer);
|
||||||
$this->composer->getInstallationManager()->addInstaller($installer);
|
$this->composer->getInstallationManager()->addInstaller($installer);
|
||||||
$this->registeredPlugins[$package->getName()] = $installer;
|
$this->registeredPlugins[$package->getName()][] = $installer;
|
||||||
} elseif (class_exists($class)) {
|
} elseif (class_exists($class)) {
|
||||||
if (!is_a($class, 'Composer\Plugin\PluginInterface', true)) {
|
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');
|
throw new \RuntimeException('Could not activate plugin "'.$package->getName().'" as "'.$class.'" does not implement Composer\Plugin\PluginInterface');
|
||||||
}
|
}
|
||||||
$plugin = new $class();
|
$plugin = new $class();
|
||||||
$this->addPlugin($plugin, $isGlobalPlugin, $package);
|
$this->addPlugin($plugin, $isGlobalPlugin, $package);
|
||||||
$this->registeredPlugins[$package->getName()] = $plugin;
|
$this->registeredPlugins[$package->getName()][] = $plugin;
|
||||||
} elseif ($failOnMissingClasses) {
|
} elseif ($failOnMissingClasses) {
|
||||||
throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class);
|
throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class);
|
||||||
}
|
}
|
||||||
|
@ -317,14 +318,16 @@ class PluginManager
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugin = $this->registeredPlugins[$package->getName()];
|
$plugins = $this->registeredPlugins[$package->getName()];
|
||||||
unset($this->registeredPlugins[$package->getName()]);
|
foreach ($plugins as $plugin) {
|
||||||
if ($plugin instanceof InstallerInterface) {
|
if ($plugin instanceof InstallerInterface) {
|
||||||
$this->composer->getInstallationManager()->removeInstaller($plugin);
|
$this->composer->getInstallationManager()->removeInstaller($plugin);
|
||||||
} else {
|
} else {
|
||||||
$this->removePlugin($plugin);
|
$this->removePlugin($plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unset($this->registeredPlugins[$package->getName()]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uninstall a plugin package
|
* Uninstall a plugin package
|
||||||
|
@ -340,15 +343,17 @@ class PluginManager
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugin = $this->registeredPlugins[$package->getName()];
|
$plugins = $this->registeredPlugins[$package->getName()];
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
if ($plugin instanceof InstallerInterface) {
|
if ($plugin instanceof InstallerInterface) {
|
||||||
$this->deactivatePackage($package);
|
$this->composer->getInstallationManager()->removeInstaller($plugin);
|
||||||
} else {
|
} else {
|
||||||
unset($this->registeredPlugins[$package->getName()]);
|
|
||||||
$this->removePlugin($plugin);
|
$this->removePlugin($plugin);
|
||||||
$this->uninstallPlugin($plugin);
|
$this->uninstallPlugin($plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unset($this->registeredPlugins[$package->getName()]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version of the internal composer-plugin-api package.
|
* Returns the version of the internal composer-plugin-api package.
|
||||||
|
|
Loading…
Reference in New Issue