From df4618838184d0c4d6dbfe30c3a2031cfa566a5a Mon Sep 17 00:00:00 2001 From: Wouter J Date: Wed, 25 Jan 2017 17:05:57 +0100 Subject: [PATCH] Improved exception message --- .../WebServerBundle/WebServerConfig.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php b/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php index 80eed60a4a..fa0b4a1fec 100644 --- a/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php +++ b/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php @@ -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,21 +87,22 @@ 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); - $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;