DumpAutoloadCommand.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Command
  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('optimize', 'o', InputOption::VALUE_NONE, 'Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.'),
  30. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules.'),
  31. ))
  32. ->setHelp(<<<EOT
  33. <info>php composer.phar dump-autoload</info>
  34. EOT
  35. )
  36. ;
  37. }
  38. protected function execute(InputInterface $input, OutputInterface $output)
  39. {
  40. $composer = $this->getComposer();
  41. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output);
  42. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  43. $installationManager = $composer->getInstallationManager();
  44. $localRepo = $composer->getRepositoryManager()->getLocalRepository();
  45. $package = $composer->getPackage();
  46. $config = $composer->getConfig();
  47. $optimize = $input->getOption('optimize') || $config->get('optimize-autoloader') || $config->get('classmap-authoritative');
  48. if ($optimize) {
  49. $output->writeln('<info>Generating optimized autoload files</info>');
  50. } else {
  51. $output->writeln('<info>Generating autoload files</info>');
  52. }
  53. $generator = $composer->getAutoloadGenerator();
  54. $generator->setDevMode(!$input->getOption('no-dev'));
  55. $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
  56. }
  57. }