W3cubDocs

/Drupal 8

protected function DrupalKernel::initializeRequestGlobals

protected DrupalKernel::initializeRequestGlobals(Request $request)

Bootstraps the legacy global request variables.

@todo D8: Eliminate this entirely in favor of Request object.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

File

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

Class

DrupalKernel
The DrupalKernel class is the core of Drupal itself.

Namespace

Drupal\Core

Code

protected function initializeRequestGlobals(Request $request) {
  global $base_url;
  // Set and derived from $base_url by this function.
  global $base_path, $base_root;
  global $base_secure_url, $base_insecure_url;

  // Create base URL.
  $base_root = $request->getSchemeAndHttpHost();
  $base_url = $base_root;

  // For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is
  // '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.
  if ($dir = rtrim(dirname($request->server->get('SCRIPT_NAME')), '\/')) {
    // Remove "core" directory if present, allowing install.php,
    // authorize.php, and others to auto-detect a base path.
    $core_position = strrpos($dir, '/core');
    if ($core_position !== FALSE && strlen($dir) - 5 == $core_position) {
      $base_path = substr($dir, 0, $core_position);
    }
    else {
      $base_path = $dir;
    }
    $base_url .= $base_path;
    $base_path .= '/';
  }
  else {
    $base_path = '/';
  }
  $base_secure_url = str_replace('http://', 'https://', $base_url);
  $base_insecure_url = str_replace('https://', 'http://', $base_url);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!DrupalKernel.php/function/DrupalKernel::initializeRequestGlobals/8.1.x