From e74556b32277b03c299efce62a75b37a4b0cbdd3 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 28 Feb 2017 10:49:14 +1300 Subject: [PATCH] API Protect Director::get_environment_type() from invoking --- src/Control/Director.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index 47a1d3766..0d5efe396 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -571,9 +571,11 @@ class Director implements TemplateGlobalProvider * - SERVER_NAME * - gethostname() * + * @param bool $respectConfig Set to false to ignore config override + * (Necessary for checking host pre-config) * @return string */ - public static function host() + public static function host($respectConfig = true) { $headerOverride = false; if (TRUSTED_PROXY) { @@ -591,13 +593,15 @@ class Director implements TemplateGlobalProvider } } - if ($host = Director::config()->uninherited('alternate_host')) { - return $host; - } + if ($respectConfig) { + if ($host = Director::config()->uninherited('alternate_host')) { + return $host; + } - if ($baseURL = Director::config()->uninherited('alternate_base_url')) { - if (preg_match('/^(http[^:]*:\/\/[^\/]+)(\/|$)/', $baseURL, $matches)) { - return parse_url($baseURL, PHP_URL_HOST); + if ($baseURL = Director::config()->uninherited('alternate_base_url')) { + if (preg_match('/^(http[^:]*:\/\/[^\/]+)(\/|$)/', $baseURL, $matches)) { + return parse_url($baseURL, PHP_URL_HOST); + } } } @@ -1173,10 +1177,11 @@ class Director implements TemplateGlobalProvider } // Check if we are running on one of the test servers - if (in_array(static::host(), self::$dev_servers)) { + // Note: Bypass config for checking environment type + if (in_array(static::host(false), self::$dev_servers)) { return 'dev'; } - if (in_array(static::host(), self::$test_servers)) { + if (in_array(static::host(false), self::$test_servers)) { return 'test'; } return 'live';