From f67f04adfb233128a840018b491170f516216d37 Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Thu, 16 Jan 2014 20:44:16 +0100 Subject: [PATCH 1/4] added config option to optimize the autoloader always --- res/composer-schema.json | 4 ++++ src/Composer/Command/ConfigCommand.php | 1 + src/Composer/Command/DumpAutoloadCommand.php | 16 +++++++++------- src/Composer/Config.php | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/res/composer-schema.json b/res/composer-schema.json index 962398447..746e6ca76 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -180,6 +180,10 @@ "type": "string", "description": "Optional string to be used as a suffix for the generated Composer autoloader. When null a random one will be generated." }, + "autoloader-optimize-always": { + "type": "boolean", + "description": "Always optimize when dumping the autoloader" + }, "prepend-autoloader": { "type": "boolean", "description": "If false, the composer autoloader will not be prepended to existing autoloaders, defaults to true." diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 89aa072ba..96c8b3ad6 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -283,6 +283,7 @@ EOT } ), 'autoloader-suffix' => array('is_string', function ($val) { return $val === 'null' ? null : $val; }), + 'autoloader-optimize-always' => array($booleanValidator, $booleanNormalizer), 'prepend-autoloader' => array($booleanValidator, $booleanNormalizer), ); $multiConfigValues = array( diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index 23ba53167..3902828b0 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -41,12 +41,6 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - if ($input->getOption('optimize')) { - $output->writeln('Generating optimized autoload files'); - } else { - $output->writeln('Generating autoload files'); - } - $composer = $this->getComposer(); $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output); @@ -57,6 +51,14 @@ EOT $package = $composer->getPackage(); $config = $composer->getConfig(); - $composer->getAutoloadGenerator()->dump($config, $localRepo, $package, $installationManager, 'composer', $input->getOption('optimize')); + $optimize = $input->getOption('optimize') || $config->get('autoloader-optimize-always'); + + if ($optimize) { + $output->writeln('Generating optimized autoload files'); + } else { + $output->writeln('Generating autoload files'); + } + + $composer->getAutoloadGenerator()->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); } } diff --git a/src/Composer/Config.php b/src/Composer/Config.php index c54bc498c..9e695094e 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -36,6 +36,7 @@ class Config 'cache-files-maxsize' => '300MiB', 'discard-changes' => false, 'autoloader-suffix' => null, + 'autoloader-optimize-always' => false, 'prepend-autoloader' => true, 'github-domains' => array('github.com'), ); From 55da519caef1e1c2d0916c107e6604e713f5fc4c Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Thu, 16 Jan 2014 22:03:04 +0100 Subject: [PATCH 2/4] added information to the docs --- doc/04-schema.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/04-schema.md b/doc/04-schema.md index f0852668d..811acfba0 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -710,6 +710,8 @@ The following options are supported: interoperability issues with other autoloaders. * **autoloader-suffix:** Defaults to `null`. String to be used as a suffix for the generated Composer autoloader. When null a random one will be generated. +* **autoloader-optimize-always** Defaults to `false`. Always optimize when dumping + the autoloader. * **github-domains:** Defaults to `["github.com"]`. A list of domains to use in github mode. This is used for GitHub Enterprise setups. * **notify-on-install:** Defaults to `true`. Composer allows repositories to From 8a221854b19faccfac524d1f810c5e7a3ce0ec28 Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Fri, 17 Jan 2014 14:43:54 +0100 Subject: [PATCH 3/4] changed name of the option to optimize-autoloader --- doc/04-schema.md | 2 +- res/composer-schema.json | 2 +- src/Composer/Command/ConfigCommand.php | 2 +- src/Composer/Command/DumpAutoloadCommand.php | 2 +- src/Composer/Config.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/04-schema.md b/doc/04-schema.md index 811acfba0..3dfff0b05 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -710,7 +710,7 @@ The following options are supported: interoperability issues with other autoloaders. * **autoloader-suffix:** Defaults to `null`. String to be used as a suffix for the generated Composer autoloader. When null a random one will be generated. -* **autoloader-optimize-always** Defaults to `false`. Always optimize when dumping +* **optimize-autoloader** Defaults to `false`. Always optimize when dumping the autoloader. * **github-domains:** Defaults to `["github.com"]`. A list of domains to use in github mode. This is used for GitHub Enterprise setups. diff --git a/res/composer-schema.json b/res/composer-schema.json index 746e6ca76..905199247 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -180,7 +180,7 @@ "type": "string", "description": "Optional string to be used as a suffix for the generated Composer autoloader. When null a random one will be generated." }, - "autoloader-optimize-always": { + "optimize-autoloader": { "type": "boolean", "description": "Always optimize when dumping the autoloader" }, diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 96c8b3ad6..bcd3beeab 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -283,7 +283,7 @@ EOT } ), 'autoloader-suffix' => array('is_string', function ($val) { return $val === 'null' ? null : $val; }), - 'autoloader-optimize-always' => array($booleanValidator, $booleanNormalizer), + 'optimize-autoloader' => array($booleanValidator, $booleanNormalizer), 'prepend-autoloader' => array($booleanValidator, $booleanNormalizer), ); $multiConfigValues = array( diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index 3902828b0..d228fb150 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -51,7 +51,7 @@ EOT $package = $composer->getPackage(); $config = $composer->getConfig(); - $optimize = $input->getOption('optimize') || $config->get('autoloader-optimize-always'); + $optimize = $input->getOption('optimize') || $config->get('optimize-autoloader'); if ($optimize) { $output->writeln('Generating optimized autoload files'); diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 9e695094e..087949ef8 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -36,7 +36,7 @@ class Config 'cache-files-maxsize' => '300MiB', 'discard-changes' => false, 'autoloader-suffix' => null, - 'autoloader-optimize-always' => false, + 'optimize-autoloader' => false, 'prepend-autoloader' => true, 'github-domains' => array('github.com'), ); From 5e5311a224179f9a9c3d32ee670b73d2ef3cd796 Mon Sep 17 00:00:00 2001 From: Robert Boloc Date: Fri, 17 Jan 2014 15:04:10 +0100 Subject: [PATCH 4/4] use optimize-autoloader config param in update and install commands --- src/Composer/Command/InstallCommand.php | 9 +++++++-- src/Composer/Command/UpdateCommand.php | 9 +++++++-- src/Composer/Installer.php | 7 ++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index a163d5ad5..955607c85 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -76,7 +76,10 @@ EOT $preferSource = false; $preferDist = false; - switch ($composer->getConfig()->get('preferred-install')) { + + $config = $composer->getConfig(); + + switch ($config->get('preferred-install')) { case 'source': $preferSource = true; break; @@ -93,6 +96,8 @@ EOT $preferDist = $input->getOption('prefer-dist'); } + $optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader'); + $install ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) @@ -100,7 +105,7 @@ EOT ->setPreferDist($preferDist) ->setDevMode(!$input->getOption('no-dev')) ->setRunScripts(!$input->getOption('no-scripts')) - ->setOptimizeAutoloader($input->getOption('optimize-autoloader')) + ->setOptimizeAutoloader($optimize) ; if ($input->getOption('no-plugins')) { diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 7a1471a65..c3c90b94d 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -81,7 +81,10 @@ EOT $preferSource = false; $preferDist = false; - switch ($composer->getConfig()->get('preferred-install')) { + + $config = $composer->getConfig(); + + switch ($config->get('preferred-install')) { case 'source': $preferSource = true; break; @@ -98,6 +101,8 @@ EOT $preferDist = $input->getOption('prefer-dist'); } + $optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader'); + $install ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) @@ -105,7 +110,7 @@ EOT ->setPreferDist($preferDist) ->setDevMode(!$input->getOption('no-dev')) ->setRunScripts(!$input->getOption('no-scripts')) - ->setOptimizeAutoloader($input->getOption('optimize-autoloader')) + ->setOptimizeAutoloader($optimize) ->setUpdate(true) ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages')) ->setWhitelistDependencies($input->getOption('with-dependencies')) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 900c14b6b..e1dbd496f 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -279,7 +279,12 @@ class Installer } // write autoloader - $this->io->write('Generating autoload files'); + if ($this->optimizeAutoloader) { + $this->io->write('Generating optimized autoload files'); + } else { + $this->io->write('Generating autoload files'); + } + $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader); if ($this->runScripts) {