Skip to content

Commit

Permalink
minor #21407 [WebServerBundle] Improved exception message (wouterj)
Browse files Browse the repository at this point in the history
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
-------

df46188 Improved exception message
  • Loading branch information
fabpot committed Feb 2, 2017
2 parents caba97a + df46188 commit 87273d9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/Symfony/Bundle/WebServerBundle/WebServerConfig.php
Expand Up @@ -28,8 +28,8 @@ public function __construct($documentRoot, $env, $address = null, $router = null
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);
Expand Down Expand Up @@ -87,21 +87,22 @@ public function getAddress()
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);

$file = sprintf('%s.php', $prefix);
if (file_exists($documentRoot.'/'.$file)) {
return $file;
foreach ($fileNames as $fileName) {
if (file_exists($documentRoot.'/'.$fileName)) {
return $fileName;
}
}
}

private function getFrontControllerFileNames($env)
{
return array('app_'.$env.'.php', 'app.php', 'index_'.$env.'.php', 'index.php');
}

private function findBestPort()
{
$port = 8000;
Expand Down

0 comments on commit 87273d9

Please sign in to comment.