UpdateCommand.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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', 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. $install
  59. ->setDryRun($input->getOption('dry-run'))
  60. ->setVerbose($input->getOption('verbose'))
  61. ->setPreferSource($input->getOption('prefer-source'))
  62. ->setPreferDist($input->getOption('prefer-dist'))
  63. ->setDevMode(!$input->getOption('no-dev'))
  64. ->setRunScripts(!$input->getOption('no-scripts'))
  65. ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
  66. ->setUpdate(true)
  67. ->setUpdateWhitelist($input->getArgument('packages'))
  68. ;
  69. if ($input->getOption('no-custom-installers')) {
  70. $install->disableCustomInstallers();
  71. }
  72. return $install->run() ? 0 : 1;
  73. }
  74. }