function DrupalKernel::initializeSettings

Same name in other branches
  1. 9 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::initializeSettings()
  2. 10 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::initializeSettings()
  3. 11.x 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
UpdateKernel::handle in core/lib/Drupal/Core/Update/UpdateKernel.php

File

core/lib/Drupal/Core/DrupalKernel.php, line 1069

Class

DrupalKernel
The DrupalKernel class is the core of Drupal itself.

Namespace

Drupal\Core

Code

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);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.