Skip to content

Commit e76561d

Browse files
committed
bug symfony#11545 [Bundle][FrameworkBundle] built-in server: exit when docroot does not exist (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Bundle][FrameworkBundle] built-in server: exit when docroot does not exist | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#6496 | License | MIT | Doc PR | 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. Commits ------- f143254 built-in server: exit when docroot does not exist
2 parents 24c4984 + f143254 commit e76561d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ protected function configure()
8181
*/
8282
protected function execute(InputInterface $input, OutputInterface $output)
8383
{
84+
$documentRoot = $input->getOption('docroot');
85+
86+
if (!is_dir($documentRoot)) {
87+
$output->writeln(sprintf('<error>The given document root directory "%s" does not exist</error>', $documentRoot));
88+
89+
return 1;
90+
}
91+
8492
$env = $this->getContainer()->getParameter('kernel.environment');
8593

8694
if ('prod' === $env) {
@@ -96,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
96104
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
97105

98106
$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
99-
$builder->setWorkingDirectory($input->getOption('docroot'));
107+
$builder->setWorkingDirectory($documentRoot);
100108
$builder->setTimeout(null);
101109
$builder->getProcess()->run(function ($type, $buffer) use ($output) {
102110
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {

0 commit comments

Comments
 (0)