Issue #1497230 by Rob Loach, pdrake, effulgentsia, beejeebus: follow-up for dependency injection - ensure t() can be called early in bootstrap.

8.0.x
catch 2012-04-24 11:14:08 +09:00
parent bc7f5c39a4
commit 7642d2466b
3 changed files with 33 additions and 38 deletions

View File

@ -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;

View File

@ -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']);
}

View File

@ -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()'));
}