minor #21407 [WebServerBundle] Improved exception message (wouterj)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[WebServerBundle] Improved exception message
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
This is a quite minor one, but imo "guessing" is something that's optional. If I don't pass value X, a script will guess value X. However, in this case, the front controller file cannot be specified. It has to be one of the "guessed" file names. That's why I renamed "guessing" to "finding".
While doing this, I also added the possible file names in the exception message to ease fixing problems.
Commits
-------
df46188381
Improved exception message
This commit is contained in:
commit
87273d9f44
@ -28,8 +28,8 @@ class WebServerConfig
|
||||
throw new \InvalidArgumentException(sprintf('The document root directory "%s" does not exist.', $documentRoot));
|
||||
}
|
||||
|
||||
if (null === $file = $this->guessFrontController($documentRoot, $env)) {
|
||||
throw new \InvalidArgumentException(sprintf('Unable to guess the front controller under "%s".', $documentRoot));
|
||||
if (null === $file = $this->findFrontController($documentRoot, $env)) {
|
||||
throw new \InvalidArgumentException(sprintf('Unable to find the front controller under "%s" (none of these files exist: %s).', $documentRoot, implode(', ', $this->getFrontControllerFileNames($env))));
|
||||
}
|
||||
|
||||
putenv('APP_FRONT_CONTROLLER='.$file);
|
||||
@ -87,19 +87,20 @@ class WebServerConfig
|
||||
return $this->hostname.':'.$this->port;
|
||||
}
|
||||
|
||||
private function guessFrontController($documentRoot, $env)
|
||||
private function findFrontController($documentRoot, $env)
|
||||
{
|
||||
foreach (array('app', 'index') as $prefix) {
|
||||
$file = sprintf('%s_%s.php', $prefix, $env);
|
||||
if (file_exists($documentRoot.'/'.$file)) {
|
||||
return $file;
|
||||
$fileNames = $this->getFrontControllerFileNames($env);
|
||||
|
||||
foreach ($fileNames as $fileName) {
|
||||
if (file_exists($documentRoot.'/'.$fileName)) {
|
||||
return $fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file = sprintf('%s.php', $prefix);
|
||||
if (file_exists($documentRoot.'/'.$file)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
private function getFrontControllerFileNames($env)
|
||||
{
|
||||
return array('app_'.$env.'.php', 'app.php', 'index_'.$env.'.php', 'index.php');
|
||||
}
|
||||
|
||||
private function findBestPort()
|
||||
|
Reference in New Issue
Block a user