function PluginManager::addPlugin
Adds a plugin, activates it and registers it with the event dispatcher
Ideally plugin packages should be registered via registerPackage, but if you use Composer programmatically and want to register a plugin class directly this is a valid way to do it.
Parameters
PluginInterface $plugin plugin instance:
?PackageInterface $sourcePackage Package from which the plugin comes from:
1 call to PluginManager::addPlugin()
- PluginManager::registerPackage in vendor/
composer/ composer/ src/ Composer/ Plugin/ PluginManager.php - Register a plugin package, activate it etc.
File
-
vendor/
composer/ composer/ src/ Composer/ Plugin/ PluginManager.php, line 371
Class
- PluginManager
- Plugin manager
Namespace
Composer\PluginCode
public function addPlugin(PluginInterface $plugin, bool $isGlobalPlugin = false, ?PackageInterface $sourcePackage = null) : void {
if ($this->arePluginsDisabled($isGlobalPlugin ? 'global' : 'local')) {
return;
}
if ($sourcePackage === null) {
trigger_error('Calling PluginManager::addPlugin without $sourcePackage is deprecated, if you are using this please get in touch with us to explain the use case', E_USER_DEPRECATED);
}
elseif (!$this->isPluginAllowed($sourcePackage->getName(), $isGlobalPlugin, true === ($sourcePackage->getExtra()['plugin-optional'] ?? false))) {
$this->io
->writeError('Skipped loading "' . get_class($plugin) . ' from ' . $sourcePackage->getName() . '" ' . ($isGlobalPlugin || $this->runningInGlobalDir ? '(installed globally) ' : '') . ' as it is not in config.allow-plugins', true, IOInterface::DEBUG);
return;
}
$details = [];
if ($sourcePackage) {
$details[] = 'from ' . $sourcePackage->getName();
}
if ($isGlobalPlugin || $this->runningInGlobalDir) {
$details[] = 'installed globally';
}
$this->io
->writeError('Loading plugin ' . get_class($plugin) . ($details ? ' (' . implode(', ', $details) . ')' : ''), true, IOInterface::DEBUG);
$this->plugins[] = $plugin;
$plugin->activate($this->composer, $this->io);
if ($plugin instanceof EventSubscriberInterface) {
$this->composer
->getEventDispatcher()
->addSubscriber($plugin);
}
}