protected function DrupalKernel::initializeSettings in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::initializeSettings()
Locate site path and initialize settings singleton.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The current request.
Throws
\Symfony\Component\HttpKernel\Exception\BadRequestHttpException In case the host name in the request is not trusted.
2 calls to DrupalKernel::initializeSettings()
- DrupalKernel::handle in core/
lib/ Drupal/ Core/ DrupalKernel.php - Handles a Request to convert it to a Response.
- UpdateKernel::handle in core/
lib/ Drupal/ Core/ Update/ UpdateKernel.php - Handles a Request to convert it to a Response.
File
- core/
lib/ Drupal/ Core/ DrupalKernel.php, line 1069
Class
- DrupalKernel
- The DrupalKernel class is the core of Drupal itself.
Namespace
Drupal\CoreCode
protected function initializeSettings(Request $request) {
$site_path = static::findSitePath($request);
$this
->setSitePath($site_path);
$class_loader_class = get_class($this->classLoader);
Settings::initialize($this->root, $site_path, $this->classLoader);
// Initialize our list of trusted HTTP Host headers to protect against
// header attacks.
$host_patterns = Settings::get('trusted_host_patterns', []);
if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
throw new BadRequestHttpException('The provided host name is not valid for this server.');
}
}
// If the class loader is still the same, possibly
// upgrade to an optimized class loader.
if ($class_loader_class == get_class($this->classLoader) && Settings::get('class_loader_auto_detect', TRUE)) {
$prefix = Settings::getApcuPrefix('class_loader', $this->root);
$loader = NULL;
// We autodetect one of the following three optimized classloaders, if
// their underlying extension exists.
if (function_exists('apcu_fetch')) {
$loader = new ApcClassLoader($prefix, $this->classLoader);
}
elseif (extension_loaded('wincache')) {
$loader = new WinCacheClassLoader($prefix, $this->classLoader);
}
elseif (extension_loaded('xcache')) {
$loader = new XcacheClassLoader($prefix, $this->classLoader);
}
if (!empty($loader)) {
$this->classLoader
->unregister();
// The optimized classloader might be persistent and store cache misses.
// For example, once a cache miss is stored in APCu clearing it on a
// specific web-head will not clear any other web-heads. Therefore
// fallback to the composer class loader that only statically caches
// misses.
$old_loader = $this->classLoader;
$this->classLoader = $loader;
// Our class loaders are prepended to ensure they come first like the
// class loader they are replacing.
$old_loader
->register(TRUE);
$loader
->register(TRUE);
}
}
}