Skip to content

Commit

Permalink
[FrameworkBundle] Fixed server:start --router relative path issue #14124
Browse files Browse the repository at this point in the history
  • Loading branch information
abulford authored and fabpot committed Apr 13, 2015
1 parent 82400f8 commit 0c1b9ba
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$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, ':')) {
Expand Down Expand Up @@ -129,7 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
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;
}

Expand Down Expand Up @@ -176,26 +181,47 @@ private function isOtherServerProcessRunning($address)
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.
*
* @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(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>');
Expand All @@ -210,6 +236,6 @@ private function createServerProcess(OutputInterface $output, $address, $documen
$router,
)));

return new Process('exec '.$script, $documentRoot, null, null, $timeout);
return new Process('exec '.$script, $documentRoot, null, null, null);
}
}

0 comments on commit 0c1b9ba

Please sign in to comment.