UpdateCommand.php 4.5 KB

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