diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 4bccc3dc4464..7f7487dea113 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -403,15 +403,7 @@ protected function installRootPackage(IOInterface $io, Config $config, $packageN throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::$stabilities))); } - $composerJson = array_merge( - // prevent version guessing from happening - array('version' => '1.0.0'), - $config->all(), - // ensure the vendor dir and its plugins does not get loaded if CWD/vendor has plugins in it - array('config' => array('vendor-dir' => Platform::getDevNull())) - ); - $factory = new Factory; - $composer = $factory->createComposer($io, $composerJson, $disablePlugins, Platform::getDevNull(), true, $disableScripts); + $composer = Factory::create($io, $config->all(), $disablePlugins === true ? true : 'local', $disableScripts); $config = $composer->getConfig(); $rm = $composer->getRepositoryManager(); diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 9248071ca42e..5cc3867df1c9 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -293,7 +293,7 @@ public static function createOutput() * @param IOInterface $io IO instance * @param array|string|null $localConfig either a configuration array or a filename to read from, if null it will * read from the default filename - * @param bool $disablePlugins Whether plugins should not be loaded + * @param bool|'local'|'global' $disablePlugins Whether plugins should not be loaded, can be set to local or global to only disable local/global plugins * @param bool $disableScripts Whether scripts should not be run * @param string|null $cwd * @param bool $fullLoad Whether to initialize everything or only main project stuff (used when loading the global composer) @@ -500,6 +500,9 @@ protected function addLocalRepository(IOInterface $io, RepositoryManager $rm, $v */ protected function createGlobalComposer(IOInterface $io, Config $config, $disablePlugins, $disableScripts, $fullLoad = false) { + // make sure if disable plugins was 'local' it is now turned off + $disablePlugins = $disablePlugins === 'global' || $disablePlugins === true; + $composer = null; try { $composer = $this->createComposer($io, $config->get('home') . '/composer.json', $disablePlugins, $config->get('home'), $fullLoad, $disableScripts); @@ -579,7 +582,7 @@ public function createArchiveManager(Config $config, Downloader\DownloadManager * @param IOInterface $io * @param Composer $composer * @param Composer $globalComposer - * @param bool $disablePlugins + * @param bool|'local'|'global' $disablePlugins Whether plugins should not be loaded, can be set to local or global to only disable local/global plugins * @return Plugin\PluginManager */ protected function createPluginManager(IOInterface $io, Composer $composer, Composer $globalComposer = null, $disablePlugins = false) @@ -635,7 +638,7 @@ protected function loadRootPackage(RepositoryManager $rm, Config $config, Versio * @param IOInterface $io IO instance * @param mixed $config either a configuration array or a filename to read from, if null it will read from * the default filename - * @param bool $disablePlugins Whether plugins should not be loaded + * @param bool|'local'|'global' $disablePlugins Whether plugins should not be loaded, can be set to local or global to only disable local/global plugins * @param bool $disableScripts Whether scripts should not be run * @return Composer */ diff --git a/src/Composer/Installer/PluginInstaller.php b/src/Composer/Installer/PluginInstaller.php index 14d8caf9b5af..af9dd2d8916f 100644 --- a/src/Composer/Installer/PluginInstaller.php +++ b/src/Composer/Installer/PluginInstaller.php @@ -53,7 +53,7 @@ public function supports($packageType) public function prepare($type, PackageInterface $package, PackageInterface $prevPackage = null) { // fail install process early if it is going to fail due to a plugin not being allowed - if (($type === 'install' || $type === 'update') && !$this->composer->getPluginManager()->arePluginsDisabled()) { + if (($type === 'install' || $type === 'update') && !$this->composer->getPluginManager()->arePluginsDisabled('local')) { $this->composer->getPluginManager()->isPluginAllowed($package->getName(), false); } diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index c3647438cb32..fdf50c4d40bd 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -47,7 +47,7 @@ class PluginManager protected $globalComposer; /** @var VersionParser */ protected $versionParser; - /** @var bool */ + /** @var bool|'local'|'global' */ protected $disablePlugins = false; /** @var array */ @@ -74,7 +74,7 @@ class PluginManager * @param IOInterface $io * @param Composer $composer * @param Composer $globalComposer - * @param bool $disablePlugins + * @param bool|'local'|'global' $disablePlugins Whether plugins should not be loaded, can be set to local or global to only disable local/global plugins */ public function __construct(IOInterface $io, Composer $composer, Composer $globalComposer = null, $disablePlugins = false) { @@ -94,15 +94,16 @@ public function __construct(IOInterface $io, Composer $composer, Composer $globa */ public function loadInstalledPlugins() { - if ($this->disablePlugins) { - return; + if (!$this->arePluginsDisabled('local')) { + $repo = $this->composer->getRepositoryManager()->getLocalRepository(); + $this->loadRepository($repo, false); } - $repo = $this->composer->getRepositoryManager()->getLocalRepository(); - $globalRepo = $this->globalComposer !== null ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; - $this->loadRepository($repo, false); - if ($globalRepo) { - $this->loadRepository($globalRepo, true); + if (!$this->arePluginsDisabled('global')) { + $globalRepo = $this->globalComposer !== null ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; + if ($globalRepo !== null) { + $this->loadRepository($globalRepo, true); + } } } @@ -113,15 +114,16 @@ public function loadInstalledPlugins() */ public function deactivateInstalledPlugins() { - if ($this->disablePlugins) { - return; + if (!$this->arePluginsDisabled('local')) { + $repo = $this->composer->getRepositoryManager()->getLocalRepository(); + $this->deactivateRepository($repo, false); } - $repo = $this->composer->getRepositoryManager()->getLocalRepository(); - $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; - $this->deactivateRepository($repo, false); - if ($globalRepo) { - $this->deactivateRepository($globalRepo, true); + if (!$this->arePluginsDisabled('global')) { + $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; + if ($globalRepo !== null) { + $this->deactivateRepository($globalRepo, true); + } } } @@ -161,7 +163,7 @@ public function getGlobalComposer() */ public function registerPackage(PackageInterface $package, $failOnMissingClasses = false, $isGlobalPlugin = false) { - if ($this->disablePlugins) { + if ($this->arePluginsDisabled($isGlobalPlugin ? 'global' : 'local')) { return; } @@ -320,10 +322,6 @@ public function registerPackage(PackageInterface $package, $failOnMissingClasses */ public function deactivatePackage(PackageInterface $package) { - if ($this->disablePlugins) { - return; - } - if (!isset($this->registeredPlugins[$package->getName()])) { return; } @@ -351,10 +349,6 @@ public function deactivatePackage(PackageInterface $package) */ public function uninstallPackage(PackageInterface $package) { - if ($this->disablePlugins) { - return; - } - if (!isset($this->registeredPlugins[$package->getName()])) { return; } @@ -394,6 +388,10 @@ protected function getPluginApiVersion() */ public function addPlugin(PluginInterface $plugin, $isGlobalPlugin = false, PackageInterface $sourcePackage = null) { + 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)) { @@ -682,11 +680,12 @@ private function parseAllowedPlugins($allowPluginsConfig, Locker $locker = null) /** * @internal * + * @param 'local'|'global' $type * @return bool */ - public function arePluginsDisabled() + public function arePluginsDisabled($type) { - return $this->disablePlugins; + return $this->disablePlugins === true || $this->disablePlugins === $type; } /**