From 0c1b9bacd871d4e623ad64a2bbff1e4bc1d62334 Mon Sep 17 00:00:00 2001 From: abulford Date: Tue, 31 Mar 2015 09:17:27 +0100 Subject: [PATCH] [FrameworkBundle] Fixed server:start --router relative path issue #14124 --- .../Command/ServerStartCommand.php | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php index 7808560835..364777e459 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php @@ -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('The given router script "%s" does not exist', $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('Unable to find PHP binary to start server'); @@ -210,6 +236,6 @@ EOF $router, ))); - return new Process('exec '.$script, $documentRoot, null, null, $timeout); + return new Process('exec '.$script, $documentRoot, null, null, null); } }