Browse Source

Disable plugins across the board when --no-plugins is specified, fixes #5509

Jordi Boggiano 8 years ago
parent
commit
7bcd336c95
2 changed files with 12 additions and 5 deletions
  1. 2 2
      src/Composer/Command/BaseCommand.php
  2. 10 3
      src/Composer/Console/Application.php

+ 2 - 2
src/Composer/Command/BaseCommand.php

@@ -40,11 +40,11 @@ abstract class BaseCommand extends Command
 
     /**
      * @param  bool              $required
-     * @param  bool              $disablePlugins
+     * @param  bool|null         $disablePlugins
      * @throws \RuntimeException
      * @return Composer
      */
-    public function getComposer($required = true, $disablePlugins = false)
+    public function getComposer($required = true, $disablePlugins = null)
     {
         if (null === $this->composer) {
             $application = $this->getApplication();

+ 10 - 3
src/Composer/Console/Application.php

@@ -58,6 +58,7 @@ class Application extends BaseApplication
 ';
 
     private $hasPluginCommands = false;
+    private $disablePluginsByDefault = false;
 
     public function __construct()
     {
@@ -108,6 +109,8 @@ class Application extends BaseApplication
      */
     public function doRun(InputInterface $input, OutputInterface $output)
     {
+        $this->disablePluginsByDefault = $input->hasParameterOption('--no-plugins');
+
         $io = $this->io = new ConsoleIO($input, $output, $this->getHelperSet());
         ErrorHandler::register($io);
 
@@ -127,7 +130,7 @@ class Application extends BaseApplication
             }
         }
 
-        if (!$input->hasParameterOption('--no-plugins') && !$this->hasPluginCommands && 'global' !== $commandName) {
+        if (!$this->disablePluginsByDefault && !$this->hasPluginCommands && 'global' !== $commandName) {
             try {
                 foreach ($this->getPluginCommands() as $command) {
                     if ($this->has($command->getName())) {
@@ -300,12 +303,16 @@ class Application extends BaseApplication
 
     /**
      * @param  bool                    $required
-     * @param  bool                    $disablePlugins
+     * @param  bool|null               $disablePlugins
      * @throws JsonValidationException
      * @return \Composer\Composer
      */
-    public function getComposer($required = true, $disablePlugins = false)
+    public function getComposer($required = true, $disablePlugins = null)
     {
+        if (null === $disablePlugins) {
+            $disablePlugins = $this->disablePluginsByDefault;
+        }
+
         if (null === $this->composer) {
             try {
                 $this->composer = Factory::create($this->io, null, $disablePlugins);