Skip to content

Commit 556eff1

Browse files
committed
backport #12489
1 parent da1c1c5 commit 556eff1

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

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

+29-13
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
/**
@@ -29,7 +30,7 @@ class ServerRunCommand extends ContainerAwareCommand
2930
*/
3031
public function isEnabled()
3132
{
32-
if (PHP_VERSION_ID < 50400) {
33+
if (PHP_VERSION_ID < 50400 || defined('HHVM_VERSION')) {
3334
return false;
3435
}
3536

@@ -99,24 +100,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
99100
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
100101
}
101102

102-
$router = $input->getOption('router') ?: $this
103-
->getContainer()
104-
->get('kernel')
105-
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
106-
;
107-
108-
if (!file_exists($router)) {
109-
$output->writeln(sprintf('<error>The given router script "%s" does not exist</error>', $router));
110-
103+
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env)) {
111104
return 1;
112105
}
113106

114-
$router = realpath($router);
115-
116107
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
117108
$output->writeln('Quit the server with CONTROL-C.');
118109

119-
$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
120110
$builder->setWorkingDirectory($documentRoot);
121111
$builder->setTimeout(null);
122112
$process = $builder->getProcess();
@@ -136,4 +126,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
136126

137127
return $process->getExitCode();
138128
}
129+
130+
private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env)
131+
{
132+
$router = $input->getOption('router') ?: $this
133+
->getContainer()
134+
->get('kernel')
135+
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
136+
;
137+
138+
if (!file_exists($router)) {
139+
$output->writeln(sprintf('<error>The given router script "%s" does not exist</error>', $router));
140+
141+
return;
142+
}
143+
144+
$router = realpath($router);
145+
$finder = new PhpExecutableFinder();
146+
147+
if (false === $binary = $finder->find()) {
148+
$output->writeln('<error>Unable to find PHP binary to run server</error>');
149+
150+
return;
151+
}
152+
153+
return new ProcessBuilder(array($binary, '-S', $input->getArgument('address'), $router));
154+
}
139155
}

0 commit comments

Comments
 (0)