InstallCommand.php 2.6 KB

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