DumpAutoloadCommand.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Command;
  12. use Composer\Plugin\CommandEvent;
  13. use Composer\Plugin\PluginEvents;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Input\InputOption;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. /**
  18. * @author Jordi Boggiano <j.boggiano@seld.be>
  19. */
  20. class DumpAutoloadCommand extends BaseCommand
  21. {
  22. protected function configure()
  23. {
  24. $this
  25. ->setName('dump-autoload')
  26. ->setAliases(array('dumpautoload'))
  27. ->setDescription('Dumps the autoloader')
  28. ->setDefinition(array(
  29. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
  30. new InputOption('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.'),
  31. new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize`.'),
  32. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules.'),
  33. ))
  34. ->setHelp(<<<EOT
  35. <info>php composer.phar dump-autoload</info>
  36. EOT
  37. )
  38. ;
  39. }
  40. protected function execute(InputInterface $input, OutputInterface $output)
  41. {
  42. $composer = $this->getComposer();
  43. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output);
  44. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  45. $installationManager = $composer->getInstallationManager();
  46. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  47. $package = $composer->getPackage();
  48. $config = $composer->getConfig();
  49. $optimize = $input->getOption('optimize') || $config->get('optimize-autoloader');
  50. $authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
  51. if ($optimize || $authoritative) {
  52. $this->getIO()->writeError('<info>Generating optimized autoload files</info>');
  53. } else {
  54. $this->getIO()->writeError('<info>Generating autoload files</info>');
  55. }
  56. $generator = $composer->getAutoloadGenerator();
  57. $generator->setDevMode(!$input->getOption('no-dev'));
  58. $generator->setClassMapAuthoritative($authoritative);
  59. $generator->setRunScripts(!$input->getOption('no-scripts'));
  60. $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
  61. }
  62. }