This PR was squashed before being merged into the 2.6 branch (closes #14129).
Discussion
----------
[FrameworkBundle] Fixed server:start --router relative path issue #14124
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #14124
| License | MIT
| Doc PR | -
This ensures that a relative path can be used to specify the router script, and that if the router script cannot be found an error is reported and the command fails.
The file path for the router script is now determined and checked prior to the child process being forked, which seems cleaner. The same change could be made in ServerRunCommand.php, or possibly in the ServerCommand base class; to keep the scope small, though, this wasn't done as part of this bug fix.
Commits
-------
0c1b9ba
[FrameworkBundle] Fixed server:start --router relative path issue #14124
This commit is contained in:
commit
85a494c12d
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user