ComposerCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @package Grav\Console\Cli
  4. *
  5. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Console\Cli;
  9. use Grav\Console\GravCommand;
  10. use Symfony\Component\Console\Input\InputOption;
  11. /**
  12. * Class ComposerCommand
  13. * @package Grav\Console\Cli
  14. */
  15. class ComposerCommand extends GravCommand
  16. {
  17. /**
  18. * @return void
  19. */
  20. protected function configure(): void
  21. {
  22. $this
  23. ->setName('composer')
  24. ->addOption(
  25. 'install',
  26. 'i',
  27. InputOption::VALUE_NONE,
  28. 'install the dependencies'
  29. )
  30. ->addOption(
  31. 'update',
  32. 'u',
  33. InputOption::VALUE_NONE,
  34. 'update the dependencies'
  35. )
  36. ->setDescription('Updates the composer vendor dependencies needed by Grav.')
  37. ->setHelp('The <info>composer</info> command updates the composer vendor dependencies needed by Grav');
  38. }
  39. /**
  40. * @return int
  41. */
  42. protected function serve(): int
  43. {
  44. $input = $this->getInput();
  45. $io = $this->getIO();
  46. $action = $input->getOption('install') ? 'install' : ($input->getOption('update') ? 'update' : 'install');
  47. if ($input->getOption('install')) {
  48. $action = 'install';
  49. }
  50. // Updates composer first
  51. $io->writeln("\nInstalling vendor dependencies");
  52. $io->writeln($this->composerUpdate(GRAV_ROOT, $action));
  53. return 0;
  54. }
  55. }