DrupalKernel.php 2.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
<?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 {

    public function registerBundles()
    {
        $bundles = array(
            new DrupalBundle(),
        );
        $modules = array_keys(system_list('module_enabled'));
        foreach ($modules as $module) {
          $class = "\Drupal\{$module}\{$module}Bundle";
          if (class_exists($class)) {
            $bundles[] = new $class();
          }
        }
        return $bundles;
    }


    /**
     * Initializes the service container.
     */
    protected function initializeContainer()
    {
        $this->container = $this->buildContainer();
        $this->container->set('kernel', $this);
        drupal_container($this->container);
    }

    /**
     * Builds the service container.
     *
     * @return ContainerBuilder The compiled service container
     */
    protected function buildContainer()
    {
        $container = $this->getContainerBuilder();
        foreach ($this->bundles as $bundle) {
            $bundle->build($container);
        }
        $container->compile();
        return $container;
    }


    /**
     * 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 the LoaderInterface class is part of the config component, which we
      // are not using, so this is badness :-/ The alternative is to not extend
      // the base Kernel class and just implement the KernelInterface.
    }
}