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 1047

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);
}
doc_Drupal
2016-10-29 09:03:02
Comments
Leave a Comment

Please login to continue.