DrupalKernel.php 2.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Definition of Drupal\Core\DrupalKernel.
 */

namespace Drupal\Core;

10
use Drupal\Core\CoreBundle;
11
12
13
14
15
16
17
18
19
20
use Symfony\Component\HttpKernel\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

/**
 * The DrupalKernel class is the core of Drupal itself.
 */
class DrupalKernel extends Kernel {

21
  public function registerBundles() {
22
    $bundles = array(
23
      new CoreBundle(),
24
    );
25

26
27
28
29
30
31
32
33
    // 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';
34

35
36
    $modules = array_keys(system_list('module_enabled'));
    foreach ($modules as $module) {
37
      $class = "\Drupal\\{$module}\\{$module}Bundle";
38
39
40
      if (class_exists($class)) {
        $bundles[] = new $class();
      }
41
    }
42
43
    return $bundles;
  }
44
45


46
47
48
  /**
   * Initializes the service container.
   */
49
  protected function initializeContainer() {
50
51
52
53
    $this->container = $this->buildContainer();
    $this->container->set('kernel', $this);
    drupal_container($this->container);
  }
54

55
56
57
58
59
  /**
   * Builds the service container.
   *
   * @return ContainerBuilder The compiled service container
   */
60
  protected function buildContainer() {
61
    $container = $this->getContainerBuilder();
katbailey's avatar
katbailey committed
62
63
64
65

    if ($bootstrap_container = drupal_container()) {
      $container->merge($bootstrap_container);
    }
66
67
    foreach ($this->bundles as $bundle) {
      $bundle->build($container);
68
    }
69
70
71
    $container->compile();
    return $container;
  }
72

73
74
75
76
77
  /**
   * Gets a new ContainerBuilder instance used to build the service container.
   *
   * @return ContainerBuilder
   */
78
  protected function getContainerBuilder() {
79
80
81
    return new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  }

82
  public function registerContainerConfiguration(LoaderInterface $loader) {
83
84
85
86
87
    // 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 :-/
  }
88
}