UpdateCommand.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Autoload\AutoloadGenerator;
  13. use Composer\DependencyResolver;
  14. use Composer\DependencyResolver\Pool;
  15. use Composer\DependencyResolver\Request;
  16. use Composer\DependencyResolver\Operation;
  17. use Composer\Package\LinkConstraint\VersionConstraint;
  18. use Composer\Repository\PlatformRepository;
  19. use Composer\Script\EventDispatcher;
  20. use Symfony\Component\Console\Input\InputInterface;
  21. use Symfony\Component\Console\Input\InputOption;
  22. use Symfony\Component\Console\Output\OutputInterface;
  23. /**
  24. * @author Jordi Boggiano <j.boggiano@seld.be>
  25. */
  26. class UpdateCommand extends Command
  27. {
  28. protected function configure()
  29. {
  30. $this
  31. ->setName('update')
  32. ->setDescription('Updates your dependencies to the latest version, and updates the composer.lock file.')
  33. ->setDefinition(array(
  34. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  35. new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
  36. new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages.'),
  37. new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages.'),
  38. ))
  39. ->setHelp(<<<EOT
  40. The <info>update</info> command reads the composer.json file from the
  41. current directory, processes it, and updates, removes or installs all the
  42. dependencies.
  43. <info>php composer.phar update</info>
  44. EOT
  45. )
  46. ;
  47. }
  48. protected function execute(InputInterface $input, OutputInterface $output)
  49. {
  50. $installCommand = $this->getApplication()->find('install');
  51. $composer = $this->getComposer();
  52. $io = $this->getApplication()->getIO();
  53. $eventDispatcher = new EventDispatcher($composer, $io);
  54. return $installCommand->install(
  55. $io,
  56. $composer,
  57. $eventDispatcher,
  58. (Boolean)$input->getOption('prefer-source'),
  59. (Boolean)$input->getOption('dry-run'),
  60. (Boolean)$input->getOption('verbose'),
  61. (Boolean)$input->getOption('no-install-recommends'),
  62. (Boolean)$input->getOption('install-suggests'),
  63. true
  64. );
  65. }
  66. }