Skip to content

Commit 954a368

Browse files
committed
[FrameworkBundle] Fix server run in case the router script does not exist
1 parent af4f959 commit 954a368

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputOption;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Process\PhpExecutableFinder;
1819
use Symfony\Component\Process\ProcessBuilder;
1920

2021
/**
@@ -99,7 +100,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
99100
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
100101
$output->writeln('Quit the server with CONTROL-C.');
101102

102-
$builder = $this->createPhpProcessBuilder($input, $output, $env);
103+
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env)) {
104+
return 1;
105+
}
106+
103107
$builder->setWorkingDirectory($documentRoot);
104108
$builder->setTimeout(null);
105109
$process = $builder->getProcess();
@@ -137,11 +141,18 @@ private function createPhpProcessBuilder(InputInterface $input, OutputInterface
137141
if (!file_exists($router)) {
138142
$output->writeln(sprintf('<error>The given router script "%s" does not exist</error>', $router));
139143

140-
return 1;
144+
return null;
141145
}
142146

143147
$router = realpath($router);
148+
$finder = new PhpExecutableFinder();
149+
150+
if (false === $binary = $finder->find()) {
151+
$output->writeln('<error>Unable to find PHP binary to run server</error>');
152+
153+
return null;
154+
}
144155

145-
return new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
156+
return new ProcessBuilder(array($binary, '-S', $input->getArgument('address'), $router));
146157
}
147158
}

0 commit comments

Comments
 (0)