function DrupalKernel::initializeRequestGlobals
Same name in other branches
- 9 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::initializeRequestGlobals()
- 8.9.x core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::initializeRequestGlobals()
- 10 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::initializeRequestGlobals()
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.
1 call to DrupalKernel::initializeRequestGlobals()
- DrupalKernel::preHandle in core/
lib/ Drupal/ Core/ DrupalKernel.php - Helper method that does request related initialization.
File
-
core/
lib/ Drupal/ Core/ DrupalKernel.php, line 1078
Class
- DrupalKernel
- The DrupalKernel class is the core of Drupal itself.
Namespace
Drupal\CoreCode
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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.