Skip to content
Snippets Groups Projects
Commit d7dd6190 authored by Katherine Bailey's avatar Katherine Bailey
Browse files

Adding the config services to the container and removing the...

Adding the config services to the container and removing the bootstrap_variables call from before the kernel boot, plus other minor adjustments
parent e54fc079
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -2450,7 +2450,7 @@ function drupal_get_bootstrap_phase() { ...@@ -2450,7 +2450,7 @@ function drupal_get_bootstrap_phase() {
* The instance of the Drupal Container used to set up and maintain object * The instance of the Drupal Container used to set up and maintain object
* instances. * instances.
*/ */
function drupal_container(ContainerBuilder $reset = NULL) { function drupal_container(Container $reset = NULL) {
// We do not use drupal_static() here because we do not have a mechanism by // We do not use drupal_static() here because we do not have a mechanism by
// which to reinitialize the stored objects, so a drupal_static_reset() call // which to reinitialize the stored objects, so a drupal_static_reset() call
// would leave Drupal in a nonfunctional state. // would leave Drupal in a nonfunctional state.
...@@ -2460,14 +2460,13 @@ function drupal_container(ContainerBuilder $reset = NULL) { ...@@ -2460,14 +2460,13 @@ function drupal_container(ContainerBuilder $reset = NULL) {
} }
elseif (!isset($container)) { elseif (!isset($container)) {
// This will only ever happen if an error has been thrown. Just build a new // This will only ever happen if an error has been thrown. Just build a new
// ContainerBuilder with only the language_interface and language_content // ContainerBuilder with only the language_interface service.
// services.
$container = new ContainerBuilder(); $container = new ContainerBuilder();
// An interface language always needs to be available for t() and other // An interface language always needs to be available for t() and other
// functions. This default is overridden by drupal_language_initialize() // functions. This default is overridden by drupal_language_initialize()
// during language negotiation. // during language negotiation.
$container->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language'); $container->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language');
$container->register(LANGUAGE_TYPE_CONTENT, 'Drupal\\Core\\Language\\Language');
} }
return $container; return $container;
} }
......
...@@ -21,6 +21,7 @@ public function build(ContainerBuilder $container) ...@@ -21,6 +21,7 @@ public function build(ContainerBuilder $container)
$info += array( $info += array(
'tags' => array(), 'tags' => array(),
'references' => array(), 'references' => array(),
'parameters' => array(),
'methods' => array(), 'methods' => array(),
'arguments' => array(), 'arguments' => array(),
); );
...@@ -32,6 +33,11 @@ public function build(ContainerBuilder $container) ...@@ -32,6 +33,11 @@ public function build(ContainerBuilder $container)
$definition = new Definition($info['class'], $references); $definition = new Definition($info['class'], $references);
foreach ($info['parameters'] as $key => $param) {
$container->setParameter($key, $param);
$definition->addArgument("%{$key}%");
}
if (isset($info['factory_class']) && isset($info['factory_method'])) { if (isset($info['factory_class']) && isset($info['factory_method'])) {
$definition->setFactoryClass($info['factory_class']); $definition->setFactoryClass($info['factory_class']);
$definition->setFactoryMethod($info['factory_method']); $definition->setFactoryMethod($info['factory_method']);
...@@ -63,6 +69,31 @@ public function build(ContainerBuilder $container) ...@@ -63,6 +69,31 @@ public function build(ContainerBuilder $container)
*/ */
function getDefinitions() { function getDefinitions() {
return array( 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( 'dispatcher' => array(
'class' => 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher', 'class' => 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher',
'references' => array( 'references' => array(
......
...@@ -18,63 +18,73 @@ ...@@ -18,63 +18,73 @@
*/ */
class DrupalKernel extends Kernel { class DrupalKernel extends Kernel {
public function registerBundles() public function registerBundles()
{ {
$bundles = array( $bundles = array(
new DrupalBundle(), new DrupalBundle(),
); );
$modules = array_keys(system_list('module_enabled'));
foreach ($modules as $module) {
$class = "\Drupal\{$module}\{$module}Bundle";
if (class_exists($class)) {
$bundles[] = new $class();
}
}
return $bundles;
}
// Rather than bootstrapping to a higher phase prior to booting the Kernel, which
// would ensure these files are loaded already, we want to boot the Kernel as
// early as possible in the bootstrapping phase.
// TODO: Somehow remove the necessity of calling system_list() to find out which
// bundles exist.
require_once DRUPAL_ROOT . '/core/includes/cache.inc';
require_once DRUPAL_ROOT . '/core/includes/module.inc';
require_once DRUPAL_ROOT . '/core/includes/database.inc';
/** $modules = array_keys(system_list('module_enabled'));
* Initializes the service container. foreach ($modules as $module) {
*/ $class = "\Drupal\{$module}\{$module}Bundle";
protected function initializeContainer() if (class_exists($class)) {
{ $bundles[] = new $class();
$this->container = $this->buildContainer(); }
$this->container->set('kernel', $this);
drupal_container($this->container);
} }
return $bundles;
}
/**
* Builds the service container.
*
* @return ContainerBuilder The compiled service container
*/
protected function buildContainer()
{
$container = $this->getContainerBuilder();
foreach ($this->bundles as $bundle) {
$bundle->build($container);
}
$container->compile();
return $container;
}
/**
* Initializes the service container.
*/
protected function initializeContainer()
{
$this->container = $this->buildContainer();
$this->container->set('kernel', $this);
drupal_container($this->container);
}
/** /**
* Gets a new ContainerBuilder instance used to build the service container. * Builds the service container.
* *
* @return ContainerBuilder * @return ContainerBuilder The compiled service container
*/ */
protected function getContainerBuilder() protected function buildContainer()
{ {
return new ContainerBuilder(new ParameterBag($this->getKernelParameters())); $container = $this->getContainerBuilder();
foreach ($this->bundles as $bundle) {
$bundle->build($container);
} }
$container->compile();
return $container;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{ /**
// We have to define this method because it's not defined in the base class, * Gets a new ContainerBuilder instance used to build the service container.
// but the LoaderInterface class is part of the config component, which we *
// are not using, so this is badness :-/ The alternative is to not extend * @return ContainerBuilder
// the base Kernel class and just implement the KernelInterface. */
} protected function getContainerBuilder()
{
return new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
// We have to define this method because it's not defined in the base class
// but is part of the KernelInterface interface. However, the LoaderInterface
// class is part of the config component, which we are not using, so this
// is badness :-/
}
} }
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
// Bootstrap the lowest level of what we need. // Bootstrap the lowest level of what we need.
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
// Create a request object from the HTTPFoundation. // Create a request object from the HTTPFoundation.
$request = Request::createFromGlobals(); $request = Request::createFromGlobals();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment