Commit ea2d59c6 authored by katbailey's avatar katbailey

Moving stuff around

parent 48ad4e8e
......@@ -6,6 +6,7 @@
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Language\Language;
......@@ -2460,38 +2461,63 @@ function drupal_container(Container $reset = NULL) {
$container = $reset;
}
elseif (!isset($container)) {
// During a normal page request, as opposed to during installation, this will only
// ever happen if an error has been thrown. We need to build a new ContainerBuilder
// with only the language_interface service.
// Return a ContainerBuilder instance with the bare essentials needed for any
// full bootstrap regardless of whether there will be a DrupalKernel involved.
// This will get merged with the full Kernel-built Container on normal page
// requests.
$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.
// functions.
$container->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language');
// If we are at the beginning of the installation process, we also need the config
// services.
if (variable_get('install_task', '') != 'done') {
// Register configuration storage dispatcher.
$container->setParameter('config.storage.info', array(
'Drupal\Core\Config\DatabaseStorage' => array(
'connection' => 'default',
'target' => 'default',
'read' => TRUE,
'write' => TRUE,
),
'Drupal\Core\Config\FileStorage' => array(
'directory' => config_get_config_directory(),
'read' => TRUE,
'write' => FALSE,
),
// Register configuration storage dispatcher.
$container->setParameter('config.storage.info', array(
'Drupal\Core\Config\DatabaseStorage' => array(
'connection' => 'default',
'target' => 'default',
'read' => TRUE,
'write' => TRUE,
),
'Drupal\Core\Config\FileStorage' => array(
'directory' => config_get_config_directory(),
'read' => TRUE,
'write' => FALSE,
),
));
$container->register('config.storage.dispatcher', 'Drupal\Core\Config\StorageDispatcher')
->addArgument('%config.storage.info%');
// Register configuration object factory.
$container->register('config.factory', 'Drupal\Core\Config\ConfigFactory')
->addArgument(new Reference('config.storage.dispatcher'));
// Ensure a language object is registered for each language type, whether the
// site is multilingual or not.
$types = language_types_get_all();
if (language_multilingual()) {
include_once DRUPAL_ROOT . '/core/includes/language.inc';
foreach ($types as $type) {
$language = language_types_initialize($type);
// We cannot pass an object as a parameter to a method on a service.
$info = get_object_vars($language);
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($info));
}
}
else {
$info = variable_get('language_default', array(
'langcode' => 'en',
'name' => 'English',
'direction' => 0,
'weight' => 0,
'locked' => 0,
));
$container->register('config.storage.dispatcher', 'Drupal\Core\Config\StorageDispatcher')
->addArgument('%config.storage.info%');
// Register configuration object factory.
$container->register('config.factory', 'Drupal\Core\Config\ConfigFactory')
->addArgument(new Reference('config.storage.dispatcher'));
$info['default'] = TRUE;
foreach ($types as $type) {
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($info));
}
}
}
return $container;
......
......@@ -13,8 +13,6 @@ class DrupalBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$definitions = $this->getDefinitions();
foreach ($definitions as $id => $info) {
......@@ -55,11 +53,12 @@ public function build(ContainerBuilder $container)
$definition->addMethodCall($method, $args);
}
if (isset($info['container_aware'])) {
$definition->addMethodCall('setContainer', array(new Reference('service_container')));
}
$container->setDefinition($id, $definition);
}
$this->registerLanguageServices($container);
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
}
......@@ -69,31 +68,6 @@ public function build(ContainerBuilder $container)
*/
function getDefinitions() {
return array(
// Register configuration storage dispatcher.
'config.storage.dispatcher' => array(
'class' => 'Drupal\Core\Config\StorageDispatcher',
'parameters' => array(
'conifg.storage.info' => array(
'Drupal\Core\Config\DatabaseStorage' => array(
'connection' => 'default',
'target' => 'default',
'read' => TRUE,
'write' => TRUE,
),
'Drupal\Core\Config\FileStorage' => array(
'directory' => config_get_config_directory(),
'read' => TRUE,
'write' => FALSE,
),
),
),
),
'config.factory' => array(
'class' => 'Drupal\Core\Config\ConfigFactory',
'references' => array(
'config.storage.dispatcher'
)
),
'dispatcher' => array(
'class' => 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher',
'references' => array(
......@@ -156,7 +130,7 @@ function getDefinitions() {
'exception_controller' => array(
'class' => 'Drupal\Core\ExceptionController',
'references' => array('content_negotiation'),
'methods' => array('setContainer' => array('service_container'))
'container_aware' => TRUE,
),
'exception_listener' => array(
'class' => 'Symfony\Component\HttpKernel\EventListener\ExceptionListener',
......@@ -177,41 +151,4 @@ function getDefinitions() {
),
);
}
/**
* Registers language-related services to the container.
*/
function registerLanguageServices($container) {
$types = language_types_get_all();
// Ensure a language object is registered for each language type, whether the
// site is multilingual or not.
if (language_multilingual()) {
include_once DRUPAL_ROOT . '/core/includes/language.inc';
foreach ($types as $type) {
$language = language_types_initialize($type);
// We cannot pass an object as a parameter to a method on a service.
$info = get_object_vars($language);
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($info));
}
}
else {
$info = variable_get('language_default', array(
'langcode' => 'en',
'name' => 'English',
'direction' => 0,
'weight' => 0,
'locked' => 0,
));
$info['default'] = TRUE;
foreach ($types as $type) {
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($info));
}
}
}
}
......@@ -62,6 +62,10 @@ protected function initializeContainer()
protected function buildContainer()
{
$container = $this->getContainerBuilder();
if ($bootstrap_container = drupal_container()) {
$container->merge($bootstrap_container);
}
foreach ($this->bundles as $bundle) {
$bundle->build($container);
}
......
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