diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index d2384cd0f..157987b9e 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/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()) diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index c452d1fb4..d47dd7284 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/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); } } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index d48170b7e..c88c555ef 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/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'); }