浏览代码

Merge remote-tracking branch 'cw-ozaki/no-script-dump-autoload'

Conflicts:
	src/Composer/Autoload/AutoloadGenerator.php
	src/Composer/Command/DumpAutoloadCommand.php
Jordi Boggiano 9 年之前
父节点
当前提交
c0b49d09f3

+ 25 - 6
src/Composer/Autoload/AutoloadGenerator.php

@@ -48,6 +48,11 @@ class AutoloadGenerator
      */
     private $classMapAuthoritative = false;
 
+    /**
+     * @var bool
+     */
+    private $runScripts = false;
+
     public function __construct(EventDispatcher $eventDispatcher, IOInterface $io = null)
     {
         $this->eventDispatcher = $eventDispatcher;
@@ -70,15 +75,27 @@ class AutoloadGenerator
         $this->classMapAuthoritative = (boolean) $classMapAuthoritative;
     }
 
+    /**
+     * Set whether to run scripts or not
+     *
+     * @param bool $runScripts
+     */
+    public function setRunScripts($runScripts = true)
+    {
+        $this->runScripts = (boolean) $runScripts;
+    }
+
     public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '')
     {
         if ($this->classMapAuthoritative) {
             // Force scanPsr0Packages when classmap is authoritative
             $scanPsr0Packages = true;
         }
-        $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array(
-            'optimize' => (bool) $scanPsr0Packages,
-        ));
+        if ($this->runScripts) {
+            $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array(
+                'optimize' => (bool) $scanPsr0Packages,
+            ));
+        }
 
         $filesystem = new Filesystem();
         $filesystem->ensureDirectoryExists($config->get('vendor-dir'));
@@ -277,9 +294,11 @@ EOF;
         $this->safeCopy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
         $this->safeCopy(__DIR__.'/../../../LICENSE', $targetDir.'/LICENSE');
 
-        $this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode, array(), array(
-            'optimize' => (bool) $scanPsr0Packages,
-        ));
+        if ($this->runScripts) {
+            $this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode, array(), array(
+                'optimize' => (bool) $scanPsr0Packages,
+            ));
+        }
     }
 
     private function addClassMapCode($filesystem, $basePath, $vendorPath, $dir, $blacklist = null, $namespaceFilter = null, array $classMap = array())

+ 2 - 0
src/Composer/Command/DumpAutoloadCommand.php

@@ -30,6 +30,7 @@ class DumpAutoloadCommand extends Command
             ->setAliases(array('dumpautoload'))
             ->setDescription('Dumps the autoloader')
             ->setDefinition(array(
+                new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
                 new InputOption('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.'),
                 new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize`.'),
                 new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules.'),
@@ -65,6 +66,7 @@ EOT
         $generator = $composer->getAutoloadGenerator();
         $generator->setDevMode(!$input->getOption('no-dev'));
         $generator->setClassMapAuthoritative($authoritative);
+        $generator->setRunScripts(!$input->getOption('no-scripts'));
         $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
     }
 }

+ 1 - 0
tests/Composer/Test/Autoload/AutoloadGeneratorTest.php

@@ -939,6 +939,7 @@ EOF;
             ->method('getCanonicalPackages')
             ->will($this->returnValue(array()));
 
+        $this->generator->setRunScripts(true);
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
     }