From 65c10daaf85732b5e216aa5d7028d3bd59f0bd91 Mon Sep 17 00:00:00 2001 From: Ruud Denivel Date: Wed, 9 Oct 2013 18:18:34 +0200 Subject: [PATCH 1/3] disable prepend option on install --- src/Composer/Autoload/AutoloadGenerator.php | 10 +++++----- src/Composer/Command/InstallCommand.php | 4 +++- src/Composer/Installer.php | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index e5cceb43a..56dffdbc2 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -37,7 +37,7 @@ class AutoloadGenerator $this->eventDispatcher = $eventDispatcher; } - 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 = '', $prepend = 'true') { $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP); @@ -180,7 +180,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)); + file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prepend)); // use stream_copy_to_stream instead of copy // to work around https://bugs.php.net/bug.php?id=64634 @@ -364,7 +364,7 @@ return ComposerAutoloaderInit$suffix::getLoader(); AUTOLOAD; } - protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath) + protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prepend) { // TODO the class ComposerAutoloaderInit should be revert to a closure // when APC has been fixed: @@ -395,7 +395,7 @@ class ComposerAutoloaderInit$suffix return self::\$loader; } - spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'), true, $prepend); self::\$loader = \$loader = new \\Composer\\Autoload\\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInit$suffix', 'loadClassLoader')); @@ -454,7 +454,7 @@ REGISTER_AUTOLOAD; } $file .= <<register(true); + \$loader->register($prepend); REGISTER_LOADER; diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 6138009a3..18ed93192 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -43,7 +43,8 @@ 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('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(<<install command reads the composer.lock file from @@ -101,6 +102,7 @@ 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')) { diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 3e9a9bf6b..b205f65b4 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -106,6 +106,7 @@ class Installer protected $update = false; protected $runScripts = true; protected $updateWhitelist = null; + protected $prepend = 'true'; /** * @var array @@ -280,7 +281,7 @@ class Installer // write autoloader $this->io->write('Generating autoload files'); - $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader); + $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader, '', $this->prepend); if ($this->runScripts) { // dispatch post event @@ -1055,6 +1056,18 @@ 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. * From 05d218604997af12e93eb6f756eeb3d5a6dd4a11 Mon Sep 17 00:00:00 2001 From: Ruud Denivel Date: Wed, 9 Oct 2013 18:27:59 +0200 Subject: [PATCH 2/3] disable prepend option on update --- src/Composer/Command/UpdateCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index ceabf7ff4..357beda6d 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -44,7 +44,8 @@ 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('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(<<update command reads the composer.json file from the @@ -107,6 +108,7 @@ 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')) { From c7bb3ad746a0182b501c29eb550e40209fbccf5c Mon Sep 17 00:00:00 2001 From: Ruud Denivel Date: Mon, 14 Oct 2013 18:38:30 +0200 Subject: [PATCH 3/3] refactor prepend autoloader from cli option to config var (prepend-autoloader) in composer.json --- src/Composer/Autoload/AutoloadGenerator.php | 11 ++++++----- src/Composer/Command/InstallCommand.php | 4 +--- src/Composer/Command/UpdateCommand.php | 4 +--- src/Composer/Config.php | 1 + src/Composer/Installer.php | 15 +-------------- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 56dffdbc2..6322bdd61 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -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($prepend); + \$loader->register($prependAutoloader); REGISTER_LOADER; diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 18ed93192..6138009a3 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -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(<<install 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')) { diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 357beda6d..ceabf7ff4 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -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(<<update 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')) { diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 601a21344..6151b4f81 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -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( diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index b205f65b4..3e9a9bf6b 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -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('Generating autoload files'); - $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. *