QuickStartCommand.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Drupal\Core\Command;
  3. use Symfony\Component\Console\Command\Command;
  4. use Symfony\Component\Console\Input\ArrayInput;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. /**
  10. * Installs a Drupal site and starts a webserver for local testing/development.
  11. *
  12. * Wraps 'install' and 'server' commands.
  13. *
  14. * @internal
  15. * This command makes no guarantee of an API for Drupal extensions.
  16. *
  17. * @see \Drupal\Core\Command\InstallCommand
  18. * @see \Drupal\Core\Command\ServerCommand
  19. */
  20. class QuickStartCommand extends Command {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. protected function configure() {
  25. $this->setName('quick-start')
  26. ->setDescription('Installs a Drupal site and runs a web server. This is not meant for production and might be too simple for custom development. It is a quick and easy way to get Drupal running.')
  27. ->addArgument('install-profile', InputArgument::OPTIONAL, 'Install profile to install the site in.')
  28. ->addOption('langcode', NULL, InputOption::VALUE_OPTIONAL, 'The language to install the site in. Defaults to en.', 'en')
  29. ->addOption('site-name', NULL, InputOption::VALUE_OPTIONAL, 'Set the site name. Defaults to Drupal.', 'Drupal')
  30. ->addOption('host', NULL, InputOption::VALUE_OPTIONAL, 'Provide a host for the server to run on. Defaults to 127.0.0.1.', '127.0.0.1')
  31. ->addOption('port', NULL, InputOption::VALUE_OPTIONAL, 'Provide a port for the server to run on. Will be determined automatically if none supplied.')
  32. ->addOption('suppress-login', 's', InputOption::VALUE_NONE, 'Disable opening a login URL in a browser.')
  33. ->addUsage('demo_umami --langcode fr')
  34. ->addUsage('standard --site-name QuickInstall --host localhost --port 8080')
  35. ->addUsage('minimal --host my-site.com --port 80');
  36. parent::configure();
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. protected function execute(InputInterface $input, OutputInterface $output) {
  42. $command = $this->getApplication()->find('install');
  43. $arguments = [
  44. 'command' => 'install',
  45. 'install-profile' => $input->getArgument('install-profile'),
  46. '--langcode' => $input->getOption('langcode'),
  47. '--site-name' => $input->getOption('site-name'),
  48. ];
  49. $installInput = new ArrayInput($arguments);
  50. $returnCode = $command->run($installInput, $output);
  51. if ($returnCode === 0) {
  52. $command = $this->getApplication()->find('server');
  53. $arguments = [
  54. 'command' => 'server',
  55. '--host' => $input->getOption('host'),
  56. '--port' => $input->getOption('port'),
  57. ];
  58. if ($input->getOption('suppress-login')) {
  59. $arguments['--suppress-login'] = TRUE;
  60. }
  61. $serverInput = new ArrayInput($arguments);
  62. $returnCode = $command->run($serverInput, $output);
  63. }
  64. return $returnCode;
  65. }
  66. }