DrupalKernel.php 2.13 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
    // TODO: Somehow remove the necessity of calling system_list() to find out which
    // bundles exist.
28

29 30
    $modules = array_keys(system_list('module_enabled'));
    foreach ($modules as $module) {
31
      $class = "\Drupal\\{$module}\\{$module}Bundle";
32 33 34
      if (class_exists($class)) {
        $bundles[] = new $class();
      }
35
    }
36 37
    return $bundles;
  }
38 39


40 41 42
  /**
   * Initializes the service container.
   */
43
  protected function initializeContainer() {
44 45 46 47
    $this->container = $this->buildContainer();
    $this->container->set('kernel', $this);
    drupal_container($this->container);
  }
48

49 50 51 52 53
  /**
   * Builds the service container.
   *
   * @return ContainerBuilder The compiled service container
   */
54
  protected function buildContainer() {
55
    $container = $this->getContainerBuilder();
katbailey's avatar
katbailey committed
56 57 58 59

    if ($bootstrap_container = drupal_container()) {
      $container->merge($bootstrap_container);
    }
60 61
    foreach ($this->bundles as $bundle) {
      $bundle->build($container);
62
    }
63 64 65
    $container->compile();
    return $container;
  }
66

67 68 69 70 71
  /**
   * Gets a new ContainerBuilder instance used to build the service container.
   *
   * @return ContainerBuilder
   */
72
  protected function getContainerBuilder() {
73 74 75
    return new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  }

76
  public function registerContainerConfiguration(LoaderInterface $loader) {
77 78 79 80 81
    // 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 :-/
  }
82
}