protected function parseGeneral()
{
// Read the config and merge it. (note: We use temp variables to prevent
// "Only variables should be passed by reference")
$tempconfig = $this->parseConfigYaml('config.yml');
$tempconfiglocal = $this->parseConfigYaml('config_local.yml');
$general = Arr::replaceRecursive($tempconfig, $tempconfiglocal);
// Make sure old settings for 'accept_file_types' are not still picked up. Before 1.5.4 we used to store them
// as a regex-like string, and we switched to an array. If we find the old style, fall back to the defaults.
if (isset($general['accept_file_types']) && !is_array($general['accept_file_types'])) {
unset($general['accept_file_types']);
}
// Merge the array with the defaults. Setting the required values that aren't already set.
$general = Arr::replaceRecursive($this->defaultConfig, $general);
// Make sure the cookie_domain for the sessions is set properly.
if (empty($general['cookies_domain'])) {
$request = Request::createFromGlobals();
if ($request->server->get('HTTP_HOST', false)) {
$hostSegments = explode(':', $request->server->get('HTTP_HOST'));
$hostname = reset($hostSegments);
} elseif ($request->server->get('SERVER_NAME', false)) {
$hostname = $request->server->get('SERVER_NAME');
} else {
$hostname = '';
}
// Don't set the domain for a cookie on a "TLD" - like 'localhost', or if the server_name is an IP-address
if (strpos($hostname, '.') > 0 && preg_match('/[a-z0-9]/i', $hostname)) {
if (preg_match('/^www[0-9]*./', $hostname)) {
$general['cookies_domain'] = '.' . preg_replace('/^www[0-9]*./', '', $hostname);
} else {
$general['cookies_domain'] = '.' . $hostname;
}
// Make sure we don't have consecutive '.'-s in the cookies_domain.
$general['cookies_domain'] = str_replace('..', '.', $general['cookies_domain']);
} else {
$general['cookies_domain'] = '';
}
}
// Make sure Bolt's mount point is OK:
$general['branding']['path'] = '/' . Str::makeSafe($general['branding']['path']);
// Set the link in branding, if provided_by is set.
$general['branding']['provided_link'] = Html::providerLink($general['branding']['provided_by']);
$general['database'] = $this->parseDatabase($general['database']);
return $general;
}