DrupalKernel.php 2.66 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

katbailey's avatar
katbailey committed
26 27
    // TODO: Remove the necessity of calling system_list() to find out which
    // bundles exist. See http://drupal.org/node/1331486
28 29
    $modules = array_keys(system_list('module_enabled'));
    foreach ($modules as $module) {
katbailey's avatar
katbailey committed
30 31
      $camelized = ContainerBuilder::camelize($module);
      $class = "\Drupal\\{$module}\\{$camelized}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() {
katbailey's avatar
katbailey committed
44 45 46
    // @todo We should be compiling the container and dumping to php so we don't
    // have to recompile every time. There is a separate issue for this, see
    // http://drupal.org/node/1668892.
47 48 49 50
    $this->container = $this->buildContainer();
    $this->container->set('kernel', $this);
    drupal_container($this->container);
  }
51

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

60
    // Merge in the minimal bootstrap container.
katbailey's avatar
katbailey committed
61 62 63
    if ($bootstrap_container = drupal_container()) {
      $container->merge($bootstrap_container);
    }
64 65
    foreach ($this->bundles as $bundle) {
      $bundle->build($container);
66
    }
67 68 69
    $container->compile();
    return $container;
  }
70

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

katbailey's avatar
katbailey committed
80
  /**
Crell's avatar
Crell committed
81 82
   * Overrides and eliminates this method from the parent class. Do not use.
   *
katbailey's avatar
katbailey committed
83 84 85 86 87 88 89
   * This method is part of the KernelInterface interface, but takes an object
   * implementing LoaderInterface as its only parameter. This is part of the
   * Config compoment from Symfony, which is not provided by Drupal core.
   *
   * Modules wishing to provide an extension to this class which uses this
   * method are responsible for ensuring the Config component exists.
   */
90
  public function registerContainerConfiguration(LoaderInterface $loader) {
91
  }
92
}