Skip to content

Commit

Permalink
[FrameworkBundle] Fix server run in case the router script does not e…
Browse files Browse the repository at this point in the history
…xist
  • Loading branch information
romainneutron committed Nov 16, 2014
1 parent af4f959 commit 1a79859
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\ProcessBuilder;

/**
Expand Down Expand Up @@ -82,6 +83,12 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (defined('HHVM_VERSION')) {
$output->writeln('<error>This command is not supported on HHVM.</error>');

return 1;
}

$documentRoot = $input->getOption('docroot');

if (!is_dir($documentRoot)) {
Expand All @@ -99,7 +106,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
$output->writeln('Quit the server with CONTROL-C.');

$builder = $this->createPhpProcessBuilder($input, $output, $env);
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env)) {
return 1;
}

$builder->setWorkingDirectory($documentRoot);
$builder->setTimeout(null);
$process = $builder->getProcess();
Expand Down Expand Up @@ -137,11 +147,18 @@ private function createPhpProcessBuilder(InputInterface $input, OutputInterface
if (!file_exists($router)) {
$output->writeln(sprintf('<error>The given router script "%s" does not exist</error>', $router));

return 1;
return;
}

$router = realpath($router);
$finder = new PhpExecutableFinder();

if (false === $binary = $finder->find()) {
$output->writeln('<error>Unable to find PHP binary to run server</error>');

return;
}

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

0 comments on commit 1a79859

Please sign in to comment.