1
0
Fork 0

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

Conflicts:
	src/Composer/Autoload/AutoloadGenerator.php
	src/Composer/Command/DumpAutoloadCommand.php
pull/4623/head
Jordi Boggiano 2015-11-21 17:14:33 +00:00
commit c0b49d09f3
3 changed files with 28 additions and 6 deletions

View File

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

View File

@ -30,6 +30,7 @@ class DumpAutoloadCommand extends Command
->setAliases(array('dumpautoload')) ->setAliases(array('dumpautoload'))
->setDescription('Dumps the autoloader') ->setDescription('Dumps the autoloader')
->setDefinition(array( ->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('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('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.'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules.'),
@ -65,6 +66,7 @@ EOT
$generator = $composer->getAutoloadGenerator(); $generator = $composer->getAutoloadGenerator();
$generator->setDevMode(!$input->getOption('no-dev')); $generator->setDevMode(!$input->getOption('no-dev'));
$generator->setClassMapAuthoritative($authoritative); $generator->setClassMapAuthoritative($authoritative);
$generator->setRunScripts(!$input->getOption('no-scripts'));
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
} }
} }

View File

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