From f14325422069ab86a2ec76c1846d73e4c2155b65 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 2 Aug 2014 09:05:01 +0200 Subject: [PATCH] built-in server: exit when docroot does not exist When the server:run command is run with an invalid document root directory (for example, when being in the app directory and not changing the document root to ../web/), the command crashes on Windows with a 267 exit code. On Linux, the server starts but just publishes internal server errors. --- .../FrameworkBundle/Command/ServerRunCommand.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php index 63588d526402..35351679103d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php @@ -81,6 +81,14 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $documentRoot = $input->getOption('docroot'); + + if (!is_dir($documentRoot)) { + $output->writeln(sprintf('The given document root directory "%s" does not exist', $documentRoot)); + + return 1; + } + $env = $this->getContainer()->getParameter('kernel.environment'); if ('prod' === $env) { @@ -96,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf("Server running on http://%s\n", $input->getArgument('address'))); $builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router)); - $builder->setWorkingDirectory($input->getOption('docroot')); + $builder->setWorkingDirectory($documentRoot); $builder->setTimeout(null); $builder->getProcess()->run(function ($type, $buffer) use ($output) { if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {