Skip to content

Commit

Permalink
bug symfony#12489 [2.5][FrameworkBundle] Fix server run in case the r…
Browse files Browse the repository at this point in the history
…outer script does not exist (romainneutron)

This PR was merged into the 2.5 branch.

Discussion
----------

[2.5][FrameworkBundle] Fix server run in case the router script does not exist

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT

I've also added the use of `Process\PhpExecutableFinder`

Commits
-------

1a79859 [FrameworkBundle] Fix server run in case the router script does not exist
  • Loading branch information
fabpot committed Nov 16, 2014
2 parents e041ff4 + 1a79859 commit 60f38de
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 60f38de

Please sign in to comment.