Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is useless, given that the command is disabled entirely on HHVM, same than on PHP 5.3 (see line 33)


$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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should probably display an error message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error message is already printed in createPhpProcessBuilder() when it returns null.

}

$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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current implementation, if createPhpProcessBuilder fails, it returns 1. The line 102 expects a ProcessBuilder :

$builder = $this->createPhpProcessBuilder($input, $output, $env);

I prefer to return null in case no builder is created. I suppose the return 1 is a wrong copy/paste when this code was inside the Command::execute method and where it was valid

}

$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));
}
}