DrupalKernel.php 2.55 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) {
katbailey's avatar
katbailey committed
31 32
      $camelized = ContainerBuilder::camelize($module);
      $class = "\Drupal\\{$module}\\{$camelized}Bundle";
33 34 35
      if (class_exists($class)) {
        $bundles[] = new $class();
      }
36
    }
37 38
    return $bundles;
  }
39 40


41 42 43
  /**
   * Initializes the service container.
   */
44
  protected function initializeContainer() {
katbailey's avatar
katbailey committed
45 46 47
    // @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.
48 49 50 51
    $this->container = $this->buildContainer();
    $this->container->set('kernel', $this);
    drupal_container($this->container);
  }
52

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

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

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

katbailey's avatar
katbailey committed
81 82 83 84 85 86 87 88
  /**
   * 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.
   */
89
  public function registerContainerConfiguration(LoaderInterface $loader) {
90
  }
91
}