[FrameworkBundle] Fix server start in case the PHP binary is not found
This commit is contained in:
parent
dba2f5fe54
commit
a6b1cfc5b8
@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,6 +71,11 @@ EOF
|
|||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
if (defined('HHVM_VERSION')) {
|
||||||
|
$output->writeln('<error>This command is not supported on HHVM.</error>');
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if (!extension_loaded('pcntl')) {
|
if (!extension_loaded('pcntl')) {
|
||||||
$output->writeln('<error>This command needs the pcntl extension to run.</error>');
|
$output->writeln('<error>This command needs the pcntl extension to run.</error>');
|
||||||
$output->writeln('You can either install it or use the <info>server:run</info> command instead to run the built-in web server.');
|
$output->writeln('You can either install it or use the <info>server:run</info> command instead to run the built-in web server.');
|
||||||
@ -105,13 +111,10 @@ EOF
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$process = $this->createServerProcess(
|
if (null === $process = $this->createServerProcess($output, $address, $input->getOption('docroot'), $input->getOption('router'), $env, null)) {
|
||||||
$address,
|
return 1;
|
||||||
$input->getOption('docroot'),
|
}
|
||||||
$input->getOption('router'),
|
|
||||||
$env,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
$process->disableOutput();
|
$process->disableOutput();
|
||||||
$process->start();
|
$process->start();
|
||||||
$lockFile = $this->getLockFile($address);
|
$lockFile = $this->getLockFile($address);
|
||||||
@ -137,6 +140,7 @@ EOF
|
|||||||
/**
|
/**
|
||||||
* Creates a process to start PHP's built-in web server.
|
* Creates a process to start PHP's built-in web server.
|
||||||
*
|
*
|
||||||
|
* @param OutputInterface $output A OutputInterface instance
|
||||||
* @param string $address IP address and port to listen to
|
* @param string $address IP address and port to listen to
|
||||||
* @param string $documentRoot The application's document root
|
* @param string $documentRoot The application's document root
|
||||||
* @param string $router The router filename
|
* @param string $router The router filename
|
||||||
@ -145,15 +149,23 @@ EOF
|
|||||||
*
|
*
|
||||||
* @return Process The process
|
* @return Process The process
|
||||||
*/
|
*/
|
||||||
private function createServerProcess($address, $documentRoot, $router, $env, $timeout = null)
|
private function createServerProcess(OutputInterface $output, $address, $documentRoot, $router, $env, $timeout = null)
|
||||||
{
|
{
|
||||||
$router = $router ?: $this
|
$router = $router ?: $this
|
||||||
->getContainer()
|
->getContainer()
|
||||||
->get('kernel')
|
->get('kernel')
|
||||||
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
|
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$finder = new PhpExecutableFinder();
|
||||||
|
if (false === $binary = $finder->find()) {
|
||||||
|
$output->writeln('<error>Unable to find PHP binary to start server</error>');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$script = implode(' ', array_map(array('Symfony\Component\Process\ProcessUtils', 'escapeArgument'), array(
|
$script = implode(' ', array_map(array('Symfony\Component\Process\ProcessUtils', 'escapeArgument'), array(
|
||||||
PHP_BINARY,
|
$binary,
|
||||||
'-S',
|
'-S',
|
||||||
$address,
|
$address,
|
||||||
$router,
|
$router,
|
||||||
|
Reference in New Issue
Block a user