public function Bundle::getContainerExtension

Returns the bundle's container extension.

@api

Return value

ExtensionInterface|null The container extension

Throws

\LogicException

Overrides BundleInterface::getContainerExtension

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Bundle/Bundle.php, line 72

Class

Bundle
An implementation of BundleInterface that adds a few conventions for DependencyInjection extensions and Console commands.

Namespace

Symfony\Component\HttpKernel\Bundle

Code

public function getContainerExtension() {
  if (null === $this->extension) {
    $basename = preg_replace('/Bundle$/', '', $this
      ->getName());
    $class = $this
      ->getNamespace() . '\\DependencyInjection\\' . $basename . 'Extension';
    if (class_exists($class)) {
      $extension = new $class();

      // check naming convention
      $expectedAlias = Container::underscore($basename);
      if ($expectedAlias != $extension
        ->getAlias()) {
        throw new \LogicException(sprintf('The extension alias for the default extension of a ' . 'bundle must be the underscored version of the ' . 'bundle name ("%s" instead of "%s")', $expectedAlias, $extension
          ->getAlias()));
      }
      $this->extension = $extension;
    }
    else {
      $this->extension = false;
    }
  }
  if ($this->extension) {
    return $this->extension;
  }
}