API Protect Director::get_environment_type() from invoking

This commit is contained in:
Damian Mooyman 2017-02-28 10:49:14 +13:00
parent ff47bc03d7
commit e74556b322

View File

@ -571,9 +571,11 @@ class Director implements TemplateGlobalProvider
* - SERVER_NAME * - SERVER_NAME
* - gethostname() * - gethostname()
* *
* @param bool $respectConfig Set to false to ignore config override
* (Necessary for checking host pre-config)
* @return string * @return string
*/ */
public static function host() public static function host($respectConfig = true)
{ {
$headerOverride = false; $headerOverride = false;
if (TRUSTED_PROXY) { if (TRUSTED_PROXY) {
@ -591,13 +593,15 @@ class Director implements TemplateGlobalProvider
} }
} }
if ($host = Director::config()->uninherited('alternate_host')) { if ($respectConfig) {
return $host; if ($host = Director::config()->uninherited('alternate_host')) {
} return $host;
}
if ($baseURL = Director::config()->uninherited('alternate_base_url')) { if ($baseURL = Director::config()->uninherited('alternate_base_url')) {
if (preg_match('/^(http[^:]*:\/\/[^\/]+)(\/|$)/', $baseURL, $matches)) { if (preg_match('/^(http[^:]*:\/\/[^\/]+)(\/|$)/', $baseURL, $matches)) {
return parse_url($baseURL, PHP_URL_HOST); 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 // 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'; return 'dev';
} }
if (in_array(static::host(), self::$test_servers)) { if (in_array(static::host(false), self::$test_servers)) {
return 'test'; return 'test';
} }
return 'live'; return 'live';