UpdateCommand.php 2.4 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\Installer;
  13. use Composer\Script\EventDispatcher;
  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 UpdateCommand extends Command
  21. {
  22. protected function configure()
  23. {
  24. $this
  25. ->setName('update')
  26. ->setDescription('Updates your dependencies to the latest version, and updates the composer.lock file.')
  27. ->setDefinition(array(
  28. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  29. new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
  30. new InputOption('install-recommends', null, InputOption::VALUE_NONE, 'Also install recommended packages.'),
  31. new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages.'),
  32. ))
  33. ->setHelp(<<<EOT
  34. The <info>update</info> command reads the composer.json file from the
  35. current directory, processes it, and updates, removes or installs all the
  36. dependencies.
  37. <info>php composer.phar update</info>
  38. EOT
  39. )
  40. ;
  41. }
  42. protected function execute(InputInterface $input, OutputInterface $output)
  43. {
  44. $composer = $this->getComposer();
  45. $io = $this->getApplication()->getIO();
  46. $eventDispatcher = new EventDispatcher($composer, $io);
  47. $install = Installer::create($io, $composer, $eventDispatcher);
  48. $install
  49. ->setDryRun($input->getOption('dry-run'))
  50. ->setVerbose($input->getOption('verbose'))
  51. ->setPreferSource($input->getOption('prefer-source'))
  52. ->setInstallRecommends($input->getOption('install-recommends'))
  53. ->setInstallSuggests($input->getOption('install-suggests'))
  54. ->setUpdate(true)
  55. ;
  56. return $install->run();
  57. }
  58. }