InstallCommand.php 2.9 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\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('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 dev-require packages.'),
  33. new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'),
  34. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
  35. new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
  36. ))
  37. ->setHelp(<<<EOT
  38. The <info>install</info> command reads the composer.json file from the
  39. current directory, processes it, and downloads and installs all the
  40. libraries and dependencies outlined in that file.
  41. <info>php composer.phar install</info>
  42. EOT
  43. )
  44. ;
  45. }
  46. protected function execute(InputInterface $input, OutputInterface $output)
  47. {
  48. $composer = $this->getComposer();
  49. $io = $this->getIO();
  50. $install = Installer::create($io, $composer);
  51. $install
  52. ->setDryRun($input->getOption('dry-run'))
  53. ->setVerbose($input->getOption('verbose'))
  54. ->setPreferSource($input->getOption('prefer-source'))
  55. ->setPreferDist($input->getOption('prefer-dist'))
  56. ->setDevMode($input->getOption('dev'))
  57. ->setRunScripts(!$input->getOption('no-scripts'))
  58. ;
  59. if ($input->getOption('no-custom-installers')) {
  60. $install->disableCustomInstallers();
  61. }
  62. return $install->run() ? 0 : 1;
  63. }
  64. }