Commit 6275cc59 authored by effulgentsia's avatar effulgentsia Committed by Crell

#1536844: Moved language, path, theme, and module initialization from...

#1536844: Moved language, path, theme, and module initialization from bootstrap to request listeners.
parent 90d20457
......@@ -84,10 +84,7 @@ function authorize_access_allowed() {
drupal_load('module', 'system');
drupal_load('module', 'user');
// We also want to have the language system available, but we do *NOT* want to
// actually call drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE), since that would
// also force us through the DRUPAL_BOOTSTRAP_PAGE_HEADER phase, which loads
// all the modules, and that's exactly what we're trying to avoid.
// Initialize the language system.
drupal_language_initialize();
// Initialize the maintenance theme for this administrative script.
......
......@@ -138,12 +138,13 @@
const DRUPAL_BOOTSTRAP_PAGE_HEADER = 5;
/**
* Seventh bootstrap phase: find out language of the page.
* Seventh bootstrap phase: load code for subsystems and modules; validate and
* fix input data.
*/
const DRUPAL_BOOTSTRAP_LANGUAGE = 6;
const DRUPAL_BOOTSTRAP_CODE = 6;
/**
* Final bootstrap phase: Drupal is fully loaded; validate and fix input data.
* Final bootstrap phase: initialize language, path, theme, and modules.
*/
const DRUPAL_BOOTSTRAP_FULL = 7;
......@@ -2045,7 +2046,7 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
DRUPAL_BOOTSTRAP_VARIABLES,
DRUPAL_BOOTSTRAP_SESSION,
DRUPAL_BOOTSTRAP_PAGE_HEADER,
DRUPAL_BOOTSTRAP_LANGUAGE,
DRUPAL_BOOTSTRAP_CODE,
DRUPAL_BOOTSTRAP_FULL,
);
// Not drupal_static(), because the only legitimate API to control this is to
......@@ -2098,12 +2099,12 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
_drupal_bootstrap_page_header();
break;
case DRUPAL_BOOTSTRAP_LANGUAGE:
drupal_language_initialize();
case DRUPAL_BOOTSTRAP_CODE:
require_once DRUPAL_ROOT . '/core/includes/common.inc';
_drupal_bootstrap_code();
break;
case DRUPAL_BOOTSTRAP_FULL:
require_once DRUPAL_ROOT . '/core/includes/common.inc';
_drupal_bootstrap_full();
break;
}
......
......@@ -5166,7 +5166,7 @@ function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) {
return (($skip_anonymous && $user->uid == 0) || ($token == drupal_get_token($value)));
}
function _drupal_bootstrap_full() {
function _drupal_bootstrap_code() {
static $called = FALSE;
if ($called) {
......@@ -5205,6 +5205,24 @@ function _drupal_bootstrap_full() {
ini_set('log_errors', 1);
ini_set('error_log', 'public://error.log');
}
}
/**
* Temporary BC function for scripts not using DrupalKernel.
*
* DrupalKernel skips this and replicates it via event listeners.
*/
function _drupal_bootstrap_full($skip = FALSE) {
static $called = FALSE;
if ($called || $skip) {
$called = TRUE;
return;
}
// Initialize language (which can strip path prefix) prior to initializing
// current_path().
drupal_language_initialize();
// Initialize current_path() prior to invoking hook_init().
drupal_path_initialize();
......
......@@ -22,6 +22,7 @@
use Drupal\Core\EventSubscriber\ViewSubscriber;
use Drupal\Core\EventSubscriber\AccessSubscriber;
use Drupal\Core\EventSubscriber\PathSubscriber;
use Drupal\Core\EventSubscriber\LegacyRequestSubscriber;
use Drupal\Core\EventSubscriber\LegacyControllerSubscriber;
use Drupal\Core\EventSubscriber\MaintenanceModeSubscriber;
use Drupal\Core\EventSubscriber\RequestCloseSubscriber;
......@@ -74,6 +75,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
$this->dispatcher->addSubscriber(new AccessSubscriber());
$this->dispatcher->addSubscriber(new MaintenanceModeSubscriber());
$this->dispatcher->addSubscriber(new PathSubscriber());
$this->dispatcher->addSubscriber(new LegacyRequestSubscriber());
$this->dispatcher->addSubscriber(new LegacyControllerSubscriber());
$this->dispatcher->addSubscriber(new RequestCloseSubscriber());
......
<?php
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @file
*
* Definition of Drupal\Core\EventSubscriber\LegacyRequestSubscriber
*/
/**
* KernelEvents::REQUEST event subscriber to initialize theme and modules.
*/
class LegacyRequestSubscriber implements EventSubscriberInterface {
/**
* @todo Document.
*/
public function onKernelRequestLegacy(GetResponseEvent $event) {
menu_set_custom_theme();
drupal_theme_initialize();
module_invoke_all('init');
// Tell Drupal it is now fully bootstrapped (for the benefit of code that
// calls drupal_get_bootstrap_phase()), but without having
// _drupal_bootstrap_full() do anything, since we've already done the
// equivalent above and in earlier listeners.
_drupal_bootstrap_full(TRUE);
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
}
/**
* Registers the methods in this class that should be listeners.
*
* @return array
* An array of event listener definitions.
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('onKernelRequestLegacy', 90);
return $events;
}
}
......@@ -68,6 +68,31 @@ public function onKernelRequestFrontPageResolve(GetResponseEvent $event) {
$this->setPath($request, $path);
}
/**
* @todo Document.
*
* @param GetResponseEvent $event
* The Event to process.
*/
public function onKernelRequestLanguageResolve(GetResponseEvent $event) {
$request = $event->getRequest();
$path = $this->extractPath($request);
// drupal_language_initialize() combines:
// - Determination of language from $request information (e.g., path).
// - Determination of language from other information (e.g., site default).
// - Population of determined language into drupal_container().
// - Removal of language code from _current_path().
// @todo Decouple the above, but for now, invoke it and update the path
// prior to front page and alias resolution. When above is decoupled, also
// add 'langcode' (determined from $request only) to $request->attributes.
_current_path($path);
drupal_language_initialize();
$path = _current_path();
$this->setPath($request, $path);
}
/**
* Decodes the path of the request.
*
......@@ -100,7 +125,8 @@ public function onKernelRequestDecodePath(GetResponseEvent $event) {
* An array of event listener definitions.
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('onKernelRequestDecodePath', 102);
$events[KernelEvents::REQUEST][] = array('onKernelRequestDecodePath', 200);
$events[KernelEvents::REQUEST][] = array('onKernelRequestLanguageResolve', 150);
$events[KernelEvents::REQUEST][] = array('onKernelRequestFrontPageResolve', 101);
$events[KernelEvents::REQUEST][] = array('onKernelRequestPathResolve', 100);
......
......@@ -439,17 +439,9 @@ function update_check_requirements($skip_warnings = FALSE) {
install_goto('core/update.php?op=info');
}
// update_fix_d8_requirements() needs to run before bootstrapping beyond path.
// So bootstrap to DRUPAL_BOOTSTRAP_LANGUAGE then include unicode.inc.
drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
include_once DRUPAL_ROOT . '/core/includes/unicode.inc';
update_fix_d8_requirements();
// Now proceed with a full bootstrap.
// Bootstrap, fix requirements, and set the maintenance theme.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
update_fix_d8_requirements();
drupal_maintenance_theme();
// Turn error reporting back on. From now on, only fatal errors (which are
......
......@@ -32,7 +32,7 @@
// injection container at some point.
request($request);
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
$dispatcher = new EventDispatcher();
$resolver = new ControllerResolver();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment