InstallCommand.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'),
  32. ))
  33. ->setHelp(<<<EOT
  34. The <info>install</info> command reads the composer.json file from the
  35. current directory, processes it, and downloads and installs all the
  36. libraries and dependencies outlined in that file.
  37. <info>php composer.phar install</info>
  38. EOT
  39. )
  40. ;
  41. }
  42. protected function execute(InputInterface $input, OutputInterface $output)
  43. {
  44. $composer = $this->getComposer();
  45. $io = $this->getIO();
  46. $install = Installer::create($io, $composer);
  47. $install
  48. ->setDryRun($input->getOption('dry-run'))
  49. ->setVerbose($input->getOption('verbose'))
  50. ->setPreferSource($input->getOption('prefer-source'))
  51. ->setDevMode($input->getOption('dev'))
  52. ;
  53. return $install->run() ? 0 : 1;
  54. }
  55. }