[FrameworkBundle] Fixed server:start --router relative path issue #14124

This commit is contained in:
abulford 2015-03-31 09:17:27 +01:00 committed by Fabien Potencier
parent 82400f8427
commit 0c1b9bacd8

View File

@ -91,6 +91,11 @@ EOF
}
$env = $this->getContainer()->getParameter('kernel.environment');
if (false === $router = $this->determineRouterScript($input->getOption('router'), $env, $output)) {
return 1;
}
$address = $input->getArgument('address');
if (false === strpos($address, ':')) {
@ -129,7 +134,7 @@ EOF
return 1;
}
if (null === $process = $this->createServerProcess($output, $address, $documentRoot, $input->getOption('router'), $env, null)) {
if (null === $process = $this->createServerProcess($output, $address, $documentRoot, $router)) {
return 1;
}
@ -176,6 +181,35 @@ EOF
return false;
}
/**
* Determine the absolute file path for the router script, using the environment to choose a standard script
* if no custom router script is specified.
*
* @param string|null $router File path of the custom router script, if set by the user; otherwise null
* @param string $env The application environment
* @param OutputInterface $output An OutputInterface instance
*
* @return string|bool The absolute file path of the router script, or false on failure
*/
private function determineRouterScript($router, $env, OutputInterface $output)
{
if (null === $router) {
$router = $this
->getContainer()
->get('kernel')
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
;
}
if (false === $path = realpath($router)) {
$output->writeln(sprintf('<error>The given router script "%s" does not exist</error>', $router));
return false;
}
return $path;
}
/**
* Creates a process to start PHP's built-in web server.
*
@ -183,19 +217,11 @@ EOF
* @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(OutputInterface $output, $address, $documentRoot, $router, $env, $timeout = null)
private function createServerProcess(OutputInterface $output, $address, $documentRoot, $router)
{
$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('<error>Unable to find PHP binary to start server</error>');
@ -210,6 +236,6 @@ EOF
$router,
)));
return new Process('exec '.$script, $documentRoot, null, null, $timeout);
return new Process('exec '.$script, $documentRoot, null, null, null);
}
}