From a6b1cfc5b8aeb3aace45345a38f993746d4487ae Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Sat, 15 Nov 2014 20:18:41 +0100 Subject: [PATCH] [FrameworkBundle] Fix server start in case the PHP binary is not found --- .../Command/ServerStartCommand.php | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php index fd5680388e..369567a9aa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; /** @@ -70,6 +71,11 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { + if (defined('HHVM_VERSION')) { + $output->writeln('This command is not supported on HHVM.'); + + return 1; + } if (!extension_loaded('pcntl')) { $output->writeln('This command needs the pcntl extension to run.'); $output->writeln('You can either install it or use the server:run command instead to run the built-in web server.'); @@ -105,13 +111,10 @@ EOF return 1; } - $process = $this->createServerProcess( - $address, - $input->getOption('docroot'), - $input->getOption('router'), - $env, - null - ); + if (null === $process = $this->createServerProcess($output, $address, $input->getOption('docroot'), $input->getOption('router'), $env, null)) { + return 1; + } + $process->disableOutput(); $process->start(); $lockFile = $this->getLockFile($address); @@ -137,23 +140,32 @@ EOF /** * Creates a process to start PHP's built-in web server. * - * @param string $address IP address and port to listen to - * @param string $documentRoot The application's document root - * @param string $router The router filename - * @param string $env The application environment - * @param int $timeout Process timeout + * @param OutputInterface $output A OutputInterface instance + * @param string $address IP address and port to listen to + * @param string $documentRoot The application's document root + * @param string $router The router filename + * @param string $env The application environment + * @param int $timeout Process timeout * * @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 ->getContainer() ->get('kernel') ->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env)) ; + + $finder = new PhpExecutableFinder(); + if (false === $binary = $finder->find()) { + $output->writeln('Unable to find PHP binary to start server'); + + return; + } + $script = implode(' ', array_map(array('Symfony\Component\Process\ProcessUtils', 'escapeArgument'), array( - PHP_BINARY, + $binary, '-S', $address, $router,