You are here

protected function ServerCommand::execute in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Command/ServerCommand.php \Drupal\Core\Command\ServerCommand::execute()
  2. 9 core/lib/Drupal/Core/Command/ServerCommand.php \Drupal\Core\Command\ServerCommand::execute()

File

core/lib/Drupal/Core/Command/ServerCommand.php, line 61

Class

ServerCommand
Runs the PHP webserver for a Drupal site for local testing/development.

Namespace

Drupal\Core\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) : int {
  $io = new SymfonyStyle($input, $output);
  $host = $input
    ->getOption('host');
  $port = $input
    ->getOption('port');
  if (!$port) {
    $port = $this
      ->findAvailablePort($host);
  }
  if (!$port) {
    $io
      ->getErrorStyle()
      ->error('Unable to automatically determine a port. Use the --port to hardcode an available port.');
  }
  try {
    $kernel = $this
      ->boot();
  } catch (ConnectionNotDefinedException $e) {
    $io
      ->getErrorStyle()
      ->error("No installation found. Use the 'install' command.");
    return 1;
  }
  return $this
    ->start($host, $port, $kernel, $input, $io);
}