1
0
Fork 0

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

pull/2314/head
Ruud Denivel 2013-10-14 18:38:30 +02:00
parent 05d2186049
commit c7bb3ad746
5 changed files with 10 additions and 25 deletions

View File

@ -37,7 +37,7 @@ class AutoloadGenerator
$this->eventDispatcher = $eventDispatcher; $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); $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP);
@ -46,6 +46,7 @@ class AutoloadGenerator
$basePath = $filesystem->normalizePath(getcwd()); $basePath = $filesystem->normalizePath(getcwd());
$vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
$useGlobalIncludePath = (bool) $config->get('use-include-path'); $useGlobalIncludePath = (bool) $config->get('use-include-path');
$prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true';
$targetDir = $vendorPath.'/'.$targetDir; $targetDir = $vendorPath.'/'.$targetDir;
$filesystem->ensureDirectoryExists($targetDir); $filesystem->ensureDirectoryExists($targetDir);
@ -180,7 +181,7 @@ EOF;
file_put_contents($targetDir.'/autoload_files.php', $includeFilesFile); file_put_contents($targetDir.'/autoload_files.php', $includeFilesFile);
} }
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); 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 // use stream_copy_to_stream instead of copy
// to work around https://bugs.php.net/bug.php?id=64634 // to work around https://bugs.php.net/bug.php?id=64634
@ -364,7 +365,7 @@ return ComposerAutoloaderInit$suffix::getLoader();
AUTOLOAD; 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 // TODO the class ComposerAutoloaderInit should be revert to a closure
// when APC has been fixed: // when APC has been fixed:
@ -395,7 +396,7 @@ class ComposerAutoloaderInit$suffix
return self::\$loader; 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(); self::\$loader = \$loader = new \\Composer\\Autoload\\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit$suffix', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'));
@ -454,7 +455,7 @@ REGISTER_AUTOLOAD;
} }
$file .= <<<REGISTER_LOADER $file .= <<<REGISTER_LOADER
\$loader->register($prepend); \$loader->register($prependAutoloader);
REGISTER_LOADER; REGISTER_LOADER;

View File

@ -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-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('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('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('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')
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
The <info>install</info> command reads the composer.lock file from The <info>install</info> command reads the composer.lock file from
@ -102,7 +101,6 @@ EOT
->setDevMode(!$input->getOption('no-dev')) ->setDevMode(!$input->getOption('no-dev'))
->setRunScripts(!$input->getOption('no-scripts')) ->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($input->getOption('optimize-autoloader')) ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
->setPrepend(!$input->getOption('no-prepend'))
; ;
if ($input->getOption('no-plugins')) { if ($input->getOption('no-plugins')) {

View File

@ -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-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('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('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('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')
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
The <info>update</info> command reads the composer.json file from the The <info>update</info> command reads the composer.json file from the
@ -108,7 +107,6 @@ EOT
->setOptimizeAutoloader($input->getOption('optimize-autoloader')) ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
->setUpdate(true) ->setUpdate(true)
->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages')) ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages'))
->setPrepend(!$input->getOption('no-prepend'))
; ;
if ($input->getOption('no-plugins')) { if ($input->getOption('no-plugins')) {

View File

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

View File

@ -106,7 +106,6 @@ class Installer
protected $update = false; protected $update = false;
protected $runScripts = true; protected $runScripts = true;
protected $updateWhitelist = null; protected $updateWhitelist = null;
protected $prepend = 'true';
/** /**
* @var array * @var array
@ -281,7 +280,7 @@ class Installer
// write autoloader // write autoloader
$this->io->write('<info>Generating autoload files</info>'); $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) { if ($this->runScripts) {
// dispatch post event // dispatch post event
@ -1056,18 +1055,6 @@ class Installer
return $this; 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. * Disables plugins.
* *