DrupalKernel.php 2.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php

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

namespace Drupal\Core;

use Drupal\Core\DrupalBundle;
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
22
23
24
25
  public function registerBundles()
  {
    $bundles = array(
      new DrupalBundle(),
    );
26

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

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


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

57
58
59
60
61
62
63
64
65
66
  /**
   * Builds the service container.
   *
   * @return ContainerBuilder The compiled service container
   */
  protected function buildContainer()
  {
    $container = $this->getContainerBuilder();
    foreach ($this->bundles as $bundle) {
      $bundle->build($container);
67
    }
68
69
70
    $container->compile();
    return $container;
  }
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

  /**
   * Gets a new ContainerBuilder instance used to build the service container.
   *
   * @return ContainerBuilder
   */
  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 :-/
  }
90
}