diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index c26ec86..a0a2869 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3,6 +3,8 @@ use Drupal\Core\Database\Database; use Symfony\Component\ClassLoader\UniversalClassLoader; use Symfony\Component\ClassLoader\ApcUniversalClassLoader; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; /** * @file @@ -2300,6 +2302,31 @@ function drupal_get_bootstrap_phase() { } /** + * Retrieves the Drupal Container to standardize object construction. + * + * Example: + * @code + * // Register the language.interface definition. + * $container = drupal_container(); + * $container->register('language.interface', 'Drupal\\Core\\Language\\Language'); + * + * // Retrieve the language.interface object. + * $language_instance = drupal_container()->get('language.instance'); + * @endcode + * + * @return Symfony\Component\DependencyInjection\ContainerBuilder + * The instance of the Drupal Container used to set up and maintain object + * instances. + */ +function drupal_container() { + $container = &drupal_static(__FUNCTION__); + if (!isset($container)) { + $container = new ContainerBuilder(); + } + return $container; +} + +/** * Returns the test prefix if this is an internal request from SimpleTest. * * @return @@ -2452,11 +2479,21 @@ function drupal_language_initialize() { $default = language_default(); foreach ($types as $type) { $GLOBALS[$type] = $default; + + // Register the language types to the Drupal Container, making sure to set + // them as default languages. + $container = drupal_container(); + $definition = new Definition('Drupal\\Core\\Language\\Language'); + $definition->setProperty('default', TRUE); + $container->setDefinition($type, $definition); } if (language_multilingual()) { include_once DRUPAL_ROOT . '/core/includes/language.inc'; foreach ($types as $type) { $GLOBALS[$type] = language_types_initialize($type); + + // @todo Register the languages to the Drupal Container here, or in + // language_types_initialize() itself. } // Allow modules to react on language system initialization in multilingual // environments. diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php new file mode 100644 index 0000000..379e94d --- /dev/null +++ b/core/lib/Drupal/Core/Language/Language.php @@ -0,0 +1,27 @@ + 'Dependency Injection system', + 'description' => 'Test that the dependency injection container system is functional.', + 'group' => 'Bootstrap', + ); + } + + /** + * Tests retrieving the language interfaces from the Drupal Container. + * + * @see drupal_language_initialize() + */ + function testRetrieveLanguageInterface() { + // Since the default language_interface service is the default Language, we + // will if they are the same via the Drupal Container. The "default" + // property is the only property changed when initially creating the + // service. + drupal_language_initialize(); + $expected = new Drupal\Core\Language\Language(); + $expected->default = TRUE; + $result = drupal_container()->get('language_interface'); + $this->assertEqual($expected, $result, t('The language interface is registered correctly.')); + } +} +