class CoreBundle

Bundle class for mandatory core services.

This is where Drupal core registers all of its compiler passes. The service definitions themselves are in core/core.services.yml with a few, documented exceptions (typically, install requirements).

Modules wishing to register services to the container should use modulename.services.yml in their respective directories.

Hierarchy

Expanded class hierarchy of CoreBundle

2 files declare their use of CoreBundle
DrupalKernel.php in drupal/core/lib/Drupal/Core/DrupalKernel.php
Definition of Drupal\Core\DrupalKernel.
install.core.inc in drupal/core/includes/install.core.inc
API functions for installing Drupal.

File

drupal/core/lib/Drupal/Core/CoreBundle.php, line 38
Definition of Drupal\Core\CoreBundle.

Namespace

Drupal\Core
View source
class CoreBundle extends Bundle {

  /**
   * Implements \Symfony\Component\HttpKernel\Bundle\BundleInterface::build().
   */
  public function build(ContainerBuilder $container) {

    // The 'request' scope and service enable services to depend on the Request
    // object and get reconstructed when the request object changes (e.g.,
    // during a subrequest).
    $container
      ->addScope(new Scope('request'));
    $this
      ->registerTwig($container);
    $this
      ->registerModuleHandler($container);
    $container
      ->addCompilerPass(new RegisterMatchersPass());
    $container
      ->addCompilerPass(new RegisterRouteFiltersPass());

    // Add a compiler pass for registering event subscribers.
    $container
      ->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
    $container
      ->addCompilerPass(new RegisterAccessChecksPass());

    // Add a compiler pass for upcasting of entity route parameters.
    $container
      ->addCompilerPass(new RegisterParamConvertersPass());
    $container
      ->addCompilerPass(new RegisterRouteEnhancersPass());

    // Add a compiler pass for registering services needing destruction.
    $container
      ->addCompilerPass(new RegisterServicesForDestructionPass());

    // Add the compiler pass that will process the tagged services.
    $container
      ->addCompilerPass(new RegisterPathProcessorsPass());
    $container
      ->addCompilerPass(new ListCacheBinsPass());

    // Add the compiler pass for appending string translators.
    $container
      ->addCompilerPass(new RegisterStringTranslatorsPass());
  }

  /**
   * Registers the module handler.
   *
   * As this is different during install, it needs to stay in PHP.
   */
  protected function registerModuleHandler(ContainerBuilder $container) {

    // The ModuleHandler manages enabled modules and provides the ability to
    // invoke hooks in all enabled modules.
    if ($container
      ->getParameter('kernel.environment') == 'install') {

      // During installation we use the non-cached version.
      $container
        ->register('module_handler', 'Drupal\\Core\\Extension\\ModuleHandler')
        ->addArgument('%container.modules%');
    }
    else {
      $container
        ->register('module_handler', 'Drupal\\Core\\Extension\\CachedModuleHandler')
        ->addArgument('%container.modules%')
        ->addArgument(new Reference('state'))
        ->addArgument(new Reference('cache.bootstrap'));
    }
  }

  /**
   * Registers Twig services.
   *
   * This method is public and static so that it can be reused in the installer.
   */
  public static function registerTwig(ContainerBuilder $container) {
    $container
      ->register('twig.loader.filesystem', 'Twig_Loader_Filesystem')
      ->addArgument(DRUPAL_ROOT);
    $container
      ->setAlias('twig.loader', 'twig.loader.filesystem');
    $container
      ->register('twig', 'Drupal\\Core\\Template\\TwigEnvironment')
      ->addArgument(new Reference('twig.loader'))
      ->addArgument(array(
      // This is saved / loaded via drupal_php_storage().
      // All files can be refreshed by clearing caches.
      // @todo ensure garbage collection of expired files.
      // When in the installer, twig_cache must be FALSE until we know the
      // files folder is writable.
      'cache' => drupal_installation_attempted() ? FALSE : settings()
        ->get('twig_cache', TRUE),
      'base_template_class' => 'Drupal\\Core\\Template\\TwigTemplate',
      // @todo Remove in followup issue
      // @see http://drupal.org/node/1712444.
      'autoescape' => FALSE,
      // @todo Remove in followup issue
      // @see http://drupal.org/node/1806538.
      'strict_variables' => FALSE,
      'debug' => settings()
        ->get('twig_debug', FALSE),
      'auto_reload' => settings()
        ->get('twig_auto_reload', NULL),
    ))
      ->addMethodCall('addExtension', array(
      new Definition('Drupal\\Core\\Template\\TwigExtension'),
    ))
      ->addMethodCall('addExtension', array(
      new Definition('Twig_Extension_Debug'),
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Bundle::$extension protected property
Bundle::$name protected property
Bundle::$reflected protected property
Bundle::boot public function Boots the Bundle. Overrides BundleInterface::boot
Bundle::getContainerExtension public function Returns the bundle's container extension. Overrides BundleInterface::getContainerExtension
Bundle::getName final public function Returns the bundle name (the class short name). Overrides BundleInterface::getName
Bundle::getNamespace public function Gets the Bundle namespace. Overrides BundleInterface::getNamespace
Bundle::getParent public function Returns the bundle parent name. Overrides BundleInterface::getParent
Bundle::getPath public function Gets the Bundle directory path. Overrides BundleInterface::getPath
Bundle::registerCommands public function Finds and registers Commands.
Bundle::shutdown public function Shutdowns the Bundle. Overrides BundleInterface::shutdown
ContainerAware::$container protected property @api
ContainerAware::setContainer public function Sets the Container associated with this Controller. Overrides ContainerAwareInterface::setContainer
CoreBundle::build public function Implements \Symfony\Component\HttpKernel\Bundle\BundleInterface::build(). Overrides Bundle::build
CoreBundle::registerModuleHandler protected function Registers the module handler.
CoreBundle::registerTwig public static function Registers Twig services.