From d45fbee6102aef0bf3e901e5c5fcf1c8e60d49ba Mon Sep 17 00:00:00 2001 From: effulgentsia Date: Tue, 8 May 2012 19:49:07 -0700 Subject: [PATCH 1/1] #1536844: Moved language, path, theme, and module initialization from bootstrap to request listeners. --- core/authorize.php | 5 +-- core/includes/bootstrap.inc | 15 +++--- core/includes/common.inc | 20 ++++++++- core/lib/Drupal/Core/DrupalKernel.php | 2 + .../EventSubscriber/LegacyRequestSubscriber.php | 48 ++++++++++++++++++++ .../Drupal/Core/EventSubscriber/PathSubscriber.php | 28 +++++++++++- core/update.php | 12 +---- index.php | 2 +- 8 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php diff --git a/core/authorize.php b/core/authorize.php index d703b33..fd0774d 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -84,10 +84,7 @@ module_list(TRUE, FALSE, FALSE, $module_list); 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. diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 1f77542..89c74f8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -138,12 +138,13 @@ const DRUPAL_BOOTSTRAP_SESSION = 4; 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; } diff --git a/core/includes/common.inc b/core/includes/common.inc index b9884c6..8437eff 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -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(); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 00b1d08..363bc7f 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -22,6 +22,7 @@ use Symfony\Component\HttpKernel\EventListener\ExceptionListener; 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 @@ class DrupalKernel extends HttpKernel { $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()); diff --git a/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php new file mode 100644 index 0000000..486a335 --- /dev/null +++ b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php @@ -0,0 +1,48 @@ +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. * * Parameters in the URL sometimes represent code-meaningful strings. It is @@ -100,7 +125,8 @@ class PathSubscriber extends PathListenerAbstract implements EventSubscriberInte * 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); diff --git a/core/update.php b/core/update.php index d75f5b6..ab050a8 100644 --- a/core/update.php +++ b/core/update.php @@ -439,17 +439,9 @@ if (is_null($op) && update_access_allowed()) { 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 diff --git a/index.php b/index.php index 6ebb47f..244d4ae 100644 --- a/index.php +++ b/index.php @@ -32,7 +32,7 @@ $request = Request::createFromGlobals(); // injection container at some point. request($request); -drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); +drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); $dispatcher = new EventDispatcher(); $resolver = new ControllerResolver(); -- 1.7.4.1