From 7642d2466b4d981cfd57b2167195693239df2f5f Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Tue, 24 Apr 2012 11:14:08 +0900 Subject: [PATCH] Issue #1497230 by Rob Loach, pdrake, effulgentsia, beejeebus: follow-up for dependency injection - ensure t() can be called early in bootstrap. --- core/includes/bootstrap.inc | 42 +++++++++++-------- core/includes/install.core.inc | 20 --------- .../translation/tests/translation_test.module | 9 ++++ 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 369fdfc1617..7dd33b59207 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2135,24 +2135,8 @@ function _drupal_bootstrap_configuration() { // Initialize the configuration, including variables from settings.php. drupal_settings_initialize(); - // Include and activate the class loader. - $loader = drupal_classloader(); - - // Register explicit vendor namespaces. - $loader->registerNamespaces(array( - // All Symfony-borrowed code lives in /core/vendor/Symfony. - 'Symfony' => DRUPAL_ROOT . '/core/vendor', - )); - // Register the Drupal namespace for classes in core as a fallback. - // This allows to register additional namespaces within the Drupal namespace - // (e.g., for modules) and avoids an additional file_exists() on the Drupal - // core namespace, since the class loader can already determine the best - // namespace match based on a string comparison. It further allows modules to - // register/overload namespaces in Drupal core. - $loader->registerNamespaceFallbacks(array( - // All Drupal-namespaced code in core lives in /core/lib/Drupal. - 'Drupal' => DRUPAL_ROOT . '/core/lib', - )); + // Activate the class loader. + drupal_classloader(); } /** @@ -2333,6 +2317,10 @@ function drupal_container($reset = FALSE) { static $container = NULL; if ($reset || !isset($container)) { $container = new ContainerBuilder(); + // An interface language always needs to be available for t() and other + // functions. This default is overridden by drupal_language_initialize() + // during language negotiation. + $container->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language'); } return $container; } @@ -2843,6 +2831,24 @@ function drupal_classloader() { $loader = new UniversalClassLoader(); break; } + + // Register explicit vendor namespaces. + $loader->registerNamespaces(array( + // All Symfony-borrowed code lives in /core/vendor/Symfony. + 'Symfony' => DRUPAL_ROOT . '/core/vendor', + )); + // Register the Drupal namespace for classes in core as a fallback. + // This allows to register additional namespaces within the Drupal namespace + // (e.g., for modules) and avoids an additional file_exists() on the Drupal + // core namespace, since the class loader can already determine the best + // namespace match based on a string comparison. It further allows modules + // to register/overload namespaces in Drupal core. + $loader->registerNamespaceFallbacks(array( + // All Drupal-namespaced code in core lives in /core/lib/Drupal. + 'Drupal' => DRUPAL_ROOT . '/core/lib', + )); + + // Register the loader with PHP. $loader->register(); } return $loader; diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 37b32812d27..36e4f77a696 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -227,26 +227,6 @@ function install_begin_request(&$install_state) { // Allow command line scripts to override server variables used by Drupal. require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; - // Ensure that the class loader is available so that we can leverage classes - // as part of the install routine. - $loader = drupal_classloader(); - - // Register explicit vendor namespaces. - $loader->registerNamespaces(array( - // All Symfony-borrowed code lives in /core/includes/Symfony. - 'Symfony' => DRUPAL_ROOT . '/core/vendor', - )); - // Register the Drupal namespace for classes in core as a fallback. - // This allows to register additional namespaces within the Drupal namespace - // (e.g., for modules) and avoids an additional file_exists() on the Drupal - // core namespace, since the class loader can already determine the best - // namespace match based on a string comparison. It further allows modules to - // register/overload namespaces in Drupal core. - $loader->registerNamespaceFallbacks(array( - // All Drupal-namespaced code in core lives in /core/includes/Drupal. - 'Drupal' => DRUPAL_ROOT . '/core/lib', - )); - if (!$install_state['interactive']) { drupal_override_server_variables($install_state['server']); } diff --git a/core/modules/translation/tests/translation_test.module b/core/modules/translation/tests/translation_test.module index e3bb4b5ff7d..3003bd7d465 100644 --- a/core/modules/translation/tests/translation_test.module +++ b/core/modules/translation/tests/translation_test.module @@ -11,3 +11,12 @@ function translation_test_node_insert($node) { drupal_write_record('node', $node, 'nid'); } + +/** + * Implements hook_boot(). + */ +function translation_test_boot() { + // We run the t() function during hook_boot() to make sure it doesn't break + // the boot process. + $translation = t("Calling the t() process during @boot.", array('@boot' => 'hook_boot()')); +}