UpdateCommand.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\Installer;
  13. use Composer\Plugin\CommandEvent;
  14. use Composer\Plugin\PluginEvents;
  15. use Symfony\Component\Console\Input\InputInterface;
  16. use Symfony\Component\Console\Input\InputOption;
  17. use Symfony\Component\Console\Input\InputArgument;
  18. use Symfony\Component\Console\Output\OutputInterface;
  19. /**
  20. * @author Jordi Boggiano <j.boggiano@seld.be>
  21. * @author Nils Adermann <naderman@naderman.de>
  22. */
  23. class UpdateCommand extends Command
  24. {
  25. protected function configure()
  26. {
  27. $this
  28. ->setName('update')
  29. ->setDescription('Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.')
  30. ->setDefinition(array(
  31. new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that should be updated, if not provided all packages are.'),
  32. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  33. new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
  34. new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
  35. new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of require-dev packages (enabled by default, only present for BC).'),
  36. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'),
  37. new InputOption('lock', null, InputOption::VALUE_NONE, 'Only updates the lock file hash to suppress warning about the lock file being out of date.'),
  38. new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Disables all plugins.'),
  39. new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'DEPRECATED: Use no-plugins instead.'),
  40. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
  41. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  42. new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
  43. new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump')
  44. ))
  45. ->setHelp(<<<EOT
  46. The <info>update</info> command reads the composer.json file from the
  47. current directory, processes it, and updates, removes or installs all the
  48. dependencies.
  49. <info>php composer.phar update</info>
  50. To limit the update operation to a few packages, you can list the package(s)
  51. you want to update as such:
  52. <info>php composer.phar update vendor/package1 foo/mypackage [...]</info>
  53. EOT
  54. )
  55. ;
  56. }
  57. protected function execute(InputInterface $input, OutputInterface $output)
  58. {
  59. if ($input->getOption('no-custom-installers')) {
  60. $output->writeln('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
  61. $input->setOption('no-plugins', true);
  62. }
  63. $composer = $this->getComposer(true, $input->getOption('no-plugins'));
  64. $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
  65. $io = $this->getIO();
  66. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'update', $input, $output);
  67. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  68. $install = Installer::create($io, $composer);
  69. $preferSource = false;
  70. $preferDist = false;
  71. switch ($composer->getConfig()->get('preferred-install')) {
  72. case 'source':
  73. $preferSource = true;
  74. break;
  75. case 'dist':
  76. $preferDist = true;
  77. break;
  78. case 'auto':
  79. default:
  80. // noop
  81. break;
  82. }
  83. if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
  84. $preferSource = $input->getOption('prefer-source');
  85. $preferDist = $input->getOption('prefer-dist');
  86. }
  87. $install
  88. ->setDryRun($input->getOption('dry-run'))
  89. ->setVerbose($input->getOption('verbose'))
  90. ->setPreferSource($preferSource)
  91. ->setPreferDist($preferDist)
  92. ->setDevMode(!$input->getOption('no-dev'))
  93. ->setRunScripts(!$input->getOption('no-scripts'))
  94. ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
  95. ->setUpdate(true)
  96. ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages'))
  97. ;
  98. if ($input->getOption('no-plugins')) {
  99. $install->disablePlugins();
  100. }
  101. return $install->run() ? 0 : 1;
  102. }
  103. }