1
0
Fork 0

Add autoloader cli options to `require` and `remove`

Update the `composer require` and `composer remove` commands to support
the `--optimize-autoloader` and `--classmap-authoritative` cli options
and associated configuration settings. All cli entry points that invoke
`Installer::run()` or `AutoloadGenerator::dump()` now have consistent
support for these autoloader optimization flags.
pull/4362/head
Bryan Davis 2015-08-18 09:54:56 -06:00 committed by Bryan Davis
parent cc2b9cfca5
commit 71cb587611
3 changed files with 23 additions and 0 deletions

View File

@ -185,6 +185,11 @@ php composer.phar require vendor/package:2.* vendor/package2:dev-master
* **--update-with-dependencies:** Also update dependencies of the newly * **--update-with-dependencies:** Also update dependencies of the newly
required packages. required packages.
* **--sort-packages:** Keep packages sorted in `composer.json`. * **--sort-packages:** Keep packages sorted in `composer.json`.
* **--optimize-autoloader (-o):** Convert PSR-0/4 autoloading to classmap to
get a faster autoloader. This is recommended especially for production, but
can take a bit of time to run so it is currently not done by default.
* **--classmap-authoritative (-a):** Autoload classes from the classmap only.
Implicitly enables `--optimize-autoloader`.
## remove ## remove
@ -208,6 +213,11 @@ uninstalled.
terminals or scripts which don't handle backspace characters. terminals or scripts which don't handle backspace characters.
* **--update-no-dev:** Run the dependency update with the --no-dev option. * **--update-no-dev:** Run the dependency update with the --no-dev option.
* **--update-with-dependencies:** Also update dependencies of the removed packages. * **--update-with-dependencies:** Also update dependencies of the removed packages.
* **--optimize-autoloader (-o):** Convert PSR-0/4 autoloading to classmap to
get a faster autoloader. This is recommended especially for production, but
can take a bit of time to run so it is currently not done by default.
* **--classmap-authoritative (-a):** Autoload classes from the classmap only.
Implicitly enables `--optimize-autoloader`.
## global ## global

View File

@ -42,6 +42,8 @@ class RemoveCommand extends Command
new InputOption('update-no-dev', null, InputOption::VALUE_NONE, 'Run the dependency update with the --no-dev option.'), new InputOption('update-no-dev', null, InputOption::VALUE_NONE, 'Run the dependency update with the --no-dev option.'),
new InputOption('update-with-dependencies', null, InputOption::VALUE_NONE, 'Allows inherited dependencies to be updated with explicit dependencies.'), new InputOption('update-with-dependencies', null, InputOption::VALUE_NONE, 'Allows inherited dependencies to be updated with explicit dependencies.'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'), new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
The <info>remove</info> command removes a package from the current The <info>remove</info> command removes a package from the current
@ -99,9 +101,14 @@ EOT
$install = Installer::create($io, $composer); $install = Installer::create($io, $composer);
$updateDevMode = !$input->getOption('update-no-dev'); $updateDevMode = !$input->getOption('update-no-dev');
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
$install $install
->setVerbose($input->getOption('verbose')) ->setVerbose($input->getOption('verbose'))
->setDevMode($updateDevMode) ->setDevMode($updateDevMode)
->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative)
->setUpdate(true) ->setUpdate(true)
->setUpdateWhitelist($packages) ->setUpdateWhitelist($packages)
->setWhitelistDependencies($input->getOption('update-with-dependencies')) ->setWhitelistDependencies($input->getOption('update-with-dependencies'))

View File

@ -48,6 +48,8 @@ class RequireCommand extends InitCommand
new InputOption('update-with-dependencies', null, InputOption::VALUE_NONE, 'Allows inherited dependencies to be updated with explicit dependencies.'), new InputOption('update-with-dependencies', null, InputOption::VALUE_NONE, 'Allows inherited dependencies to be updated with explicit dependencies.'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'), new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
new InputOption('sort-packages', null, InputOption::VALUE_NONE, 'Sorts packages when adding/updating a new dependency'), new InputOption('sort-packages', null, InputOption::VALUE_NONE, 'Sorts packages when adding/updating a new dependency'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
The require command adds required packages to your composer.json and installs them. The require command adds required packages to your composer.json and installs them.
@ -132,6 +134,8 @@ EOT
return 0; return 0;
} }
$updateDevMode = !$input->getOption('update-no-dev'); $updateDevMode = !$input->getOption('update-no-dev');
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
$authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
// Update packages // Update packages
$this->resetComposer(); $this->resetComposer();
@ -149,6 +153,8 @@ EOT
->setPreferSource($input->getOption('prefer-source')) ->setPreferSource($input->getOption('prefer-source'))
->setPreferDist($input->getOption('prefer-dist')) ->setPreferDist($input->getOption('prefer-dist'))
->setDevMode($updateDevMode) ->setDevMode($updateDevMode)
->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative)
->setUpdate(true) ->setUpdate(true)
->setUpdateWhitelist(array_keys($requirements)) ->setUpdateWhitelist(array_keys($requirements))
->setWhitelistDependencies($input->getOption('update-with-dependencies')) ->setWhitelistDependencies($input->getOption('update-with-dependencies'))