InstallCommand.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Output\OutputInterface;
  16. /**
  17. * @author Jordi Boggiano <j.boggiano@seld.be>
  18. * @author Ryan Weaver <ryan@knplabs.com>
  19. * @author Konstantin Kudryashov <ever.zet@gmail.com>
  20. */
  21. class InstallCommand extends Command
  22. {
  23. protected function configure()
  24. {
  25. $this
  26. ->setName('install')
  27. ->setDescription('Parses the composer.json file and downloads the needed dependencies.')
  28. ->setDefinition(array(
  29. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  30. new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
  31. new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages (ignored when installing from an existing lock file).'),
  32. new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages (ignored when installing from an existing lock file).'),
  33. ))
  34. ->setHelp(<<<EOT
  35. The <info>install</info> command reads the composer.json file from the
  36. current directory, processes it, and downloads and installs all the
  37. libraries and dependencies outlined in that file.
  38. <info>php composer.phar install</info>
  39. EOT
  40. )
  41. ;
  42. }
  43. protected function execute(InputInterface $input, OutputInterface $output)
  44. {
  45. $composer = $this->getComposer();
  46. $io = $this->getApplication()->getIO();
  47. $install = Installer::create($io, $composer);
  48. $install
  49. ->setDryRun($input->getOption('dry-run'))
  50. ->setVerbose($input->getOption('verbose'))
  51. ->setPreferSource($input->getOption('prefer-source'))
  52. ->setInstallRecommends(!$input->getOption('no-install-recommends'))
  53. ->setInstallSuggests($input->getOption('install-suggests'))
  54. ;
  55. return $install->run() ? 0 : 1;
  56. }
  57. }