refactor prepend autoloader from cli option to config var (prepend-autoloader) in composer.json

main
Ruud Denivel 11 years ago
parent 05d2186049
commit c7bb3ad746

@ -37,7 +37,7 @@ class AutoloadGenerator
$this->eventDispatcher = $eventDispatcher;
}
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '', $prepend = 'true')
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '')
{
$this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP);
@ -46,6 +46,7 @@ class AutoloadGenerator
$basePath = $filesystem->normalizePath(getcwd());
$vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
$useGlobalIncludePath = (bool) $config->get('use-include-path');
$prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true';
$targetDir = $vendorPath.'/'.$targetDir;
$filesystem->ensureDirectoryExists($targetDir);
@ -180,7 +181,7 @@ EOF;
file_put_contents($targetDir.'/autoload_files.php', $includeFilesFile);
}
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prepend));
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader));
// use stream_copy_to_stream instead of copy
// to work around https://bugs.php.net/bug.php?id=64634
@ -364,7 +365,7 @@ return ComposerAutoloaderInit$suffix::getLoader();
AUTOLOAD;
}
protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prepend)
protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)
{
// TODO the class ComposerAutoloaderInit should be revert to a closure
// when APC has been fixed:
@ -395,7 +396,7 @@ class ComposerAutoloaderInit$suffix
return self::\$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'), true, $prepend);
spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'), true, $prependAutoloader);
self::\$loader = \$loader = new \\Composer\\Autoload\\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'));
@ -454,7 +455,7 @@ REGISTER_AUTOLOAD;
}
$file .= <<<REGISTER_LOADER
\$loader->register($prepend);
\$loader->register($prependAutoloader);
REGISTER_LOADER;

@ -43,8 +43,7 @@ class InstallCommand extends Command
new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
new InputOption('no-prepend', null, InputOption::VALUE_NONE, 'Disables the prepending of the autoloader')
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump')
))
->setHelp(<<<EOT
The <info>install</info> command reads the composer.lock file from
@ -102,7 +101,6 @@ EOT
->setDevMode(!$input->getOption('no-dev'))
->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
->setPrepend(!$input->getOption('no-prepend'))
;
if ($input->getOption('no-plugins')) {

@ -44,8 +44,7 @@ class UpdateCommand extends Command
new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
new InputOption('no-prepend', null, InputOption::VALUE_NONE, 'Disables the prepending of the autoloader')
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump')
))
->setHelp(<<<EOT
The <info>update</info> command reads the composer.json file from the
@ -108,7 +107,6 @@ EOT
->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
->setUpdate(true)
->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages'))
->setPrepend(!$input->getOption('no-prepend'))
;
if ($input->getOption('no-plugins')) {

@ -35,6 +35,7 @@ class Config
'cache-files-ttl' => null, // fallback to cache-ttl
'cache-files-maxsize' => '300MiB',
'discard-changes' => false,
'prepend-autoloader' => true,
);
public static $defaultRepositories = array(

@ -106,7 +106,6 @@ class Installer
protected $update = false;
protected $runScripts = true;
protected $updateWhitelist = null;
protected $prepend = 'true';
/**
* @var array
@ -281,7 +280,7 @@ class Installer
// write autoloader
$this->io->write('<info>Generating autoload files</info>');
$this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader, '', $this->prepend);
$this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
if ($this->runScripts) {
// dispatch post event
@ -1056,18 +1055,6 @@ class Installer
return $this;
}
/**
* Generate autoload_real with/without prepend
*
* @param boolean $prepend
* @return Installer
*/
public function setPrepend($prepend = true)
{
$this->prepend = (boolean) $prepend === true ? 'true' : 'false';
return $this;
}
/**
* Disables plugins.
*

Loading…
Cancel
Save