DrupalKernel.php 2.53 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
    $modules = array_keys(system_list('module_enabled'));
    foreach ($modules as $module) {
38
      $class = "\Drupal\\{$module}\\{$module}Bundle";
39 40 41
      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
  /**
   * Builds the service container.
   *
   * @return ContainerBuilder The compiled service container
   */
  protected function buildContainer()
  {
    $container = $this->getContainerBuilder();
katbailey's avatar
katbailey committed
65 66 67 68

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

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

  /**
   * 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 :-/
  }
94
}