protected function Kernel::initializeBundles

Initializes the data structures related to the bundle management.

  • the bundles property maps a bundle name to the bundle instance,
  • the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first).

Throws

\LogicException if two bundles share a common name

\LogicException if a bundle tries to extend a non-registered bundle

\LogicException if a bundle tries to extend itself

\LogicException if two bundles extend the same ancestor

3 calls to Kernel::initializeBundles()
DrupalKernel::buildContainer in drupal/core/lib/Drupal/Core/DrupalKernel.php
Builds the service container.
Kernel::boot in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Kernel.php
Boots the current kernel.
KernelForTest::initializeBundles in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php
Initializes the data structures related to the bundle management.
1 method overrides Kernel::initializeBundles()
KernelForTest::initializeBundles in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php
Initializes the data structures related to the bundle management.

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Kernel.php, line 497

Class

Kernel
The Kernel is the heart of the Symfony system.

Namespace

Symfony\Component\HttpKernel

Code

protected function initializeBundles() {

  // init bundles
  $this->bundles = array();
  $topMostBundles = array();
  $directChildren = array();
  foreach ($this
    ->registerBundles() as $bundle) {
    $name = $bundle
      ->getName();
    if (isset($this->bundles[$name])) {
      throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
    }
    $this->bundles[$name] = $bundle;
    if ($parentName = $bundle
      ->getParent()) {
      if (isset($directChildren[$parentName])) {
        throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
      }
      if ($parentName == $name) {
        throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
      }
      $directChildren[$parentName] = $name;
    }
    else {
      $topMostBundles[$name] = $bundle;
    }
  }

  // look for orphans
  if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
    throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  }

  // inheritance
  $this->bundleMap = array();
  foreach ($topMostBundles as $name => $bundle) {
    $bundleMap = array(
      $bundle,
    );
    $hierarchy = array(
      $name,
    );
    while (isset($directChildren[$name])) {
      $name = $directChildren[$name];
      array_unshift($bundleMap, $this->bundles[$name]);
      $hierarchy[] = $name;
    }
    foreach ($hierarchy as $bundle) {
      $this->bundleMap[$bundle] = $bundleMap;
      array_pop($bundleMap);
    }
  }
}