InstallCommand.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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('Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.')
  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 require-dev packages (enabled by default, only present for BC).'),
  33. new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'),
  34. new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Disables all plugins.'),
  35. new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'DEPRECATED: Use no-plugins instead.'),
  36. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
  37. new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
  38. new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
  39. new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump')
  40. ))
  41. ->setHelp(<<<EOT
  42. The <info>install</info> command reads the composer.lock file from
  43. the current directory, processes it, and downloads and installs all the
  44. libraries and dependencies outlined in that file. If the file does not
  45. exist it will look for composer.json and do the same.
  46. <info>php composer.phar install</info>
  47. EOT
  48. )
  49. ;
  50. }
  51. protected function execute(InputInterface $input, OutputInterface $output)
  52. {
  53. $composer = $this->getComposer();
  54. $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
  55. $io = $this->getIO();
  56. $install = Installer::create($io, $composer);
  57. $preferSource = false;
  58. $preferDist = false;
  59. switch ($composer->getConfig()->get('preferred-install')) {
  60. case 'source':
  61. $preferSource = true;
  62. break;
  63. case 'dist':
  64. $preferDist = true;
  65. break;
  66. case 'auto':
  67. default:
  68. // noop
  69. break;
  70. }
  71. if ($input->getOption('prefer-source') || $input->getOption('prefer-dist')) {
  72. $preferSource = $input->getOption('prefer-source');
  73. $preferDist = $input->getOption('prefer-dist');
  74. }
  75. $install
  76. ->setDryRun($input->getOption('dry-run'))
  77. ->setVerbose($input->getOption('verbose'))
  78. ->setPreferSource($preferSource)
  79. ->setPreferDist($preferDist)
  80. ->setDevMode(!$input->getOption('no-dev'))
  81. ->setRunScripts(!$input->getOption('no-scripts'))
  82. ->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
  83. ;
  84. if ($input->getOption('no-custom-installers')) {
  85. $output->writeln('<warning>You are using the deprecated option "no-custom-installers". Use "no-plugins" instead.</warning>');
  86. $input->setOption('no-plugins', true);
  87. }
  88. if ($input->getOption('no-plugins')) {
  89. $install->disablePlugins();
  90. }
  91. return $install->run() ? 0 : 1;
  92. }
  93. }