Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Bundle.php

class Bundle

Same name in this branch
  1. 11.1.x core/modules/views/src/Plugin/views/filter/Bundle.php \Drupal\views\Plugin\views\filter\Bundle

An implementation of BundleInterface that adds a few conventions for DependencyInjection extensions.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\HttpKernel\Bundle\Bundle implements \Symfony\Component\HttpKernel\Bundle\BundleInterface

Expanded class hierarchy of Bundle

116 string references to 'Bundle'
block_content_body_field.yml in core/modules/block_content/migrations/block_content_body_field.yml
core/modules/block_content/migrations/block_content_body_field.yml
block_content_entity_display.yml in core/modules/block_content/migrations/block_content_entity_display.yml
core/modules/block_content/migrations/block_content_entity_display.yml
block_content_entity_form_display.yml in core/modules/block_content/migrations/block_content_entity_form_display.yml
core/modules/block_content/migrations/block_content_entity_form_display.yml
Bundle::init in core/modules/views/src/Plugin/views/filter/Bundle.php
Overrides \Drupal\views\Plugin\views\HandlerBase::init().
BundleConstraint::getDefaultOption in core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraint.php
Returns the name of the default option.

... See full list

File

vendor/symfony/http-kernel/Bundle/Bundle.php, line 25

Namespace

Symfony\Component\HttpKernel\Bundle
View source
abstract class Bundle implements BundleInterface {
    protected string $name;
    protected ExtensionInterface|false|null $extension = null;
    protected string $path;
    protected ?ContainerInterface $container;
    private string $namespace;
    
    /**
     * @return void
     */
    public function boot() {
    }
    
    /**
     * @return void
     */
    public function shutdown() {
    }
    
    /**
     * This method can be overridden to register compilation passes,
     * other extensions, ...
     *
     * @return void
     */
    public function build(ContainerBuilder $container) {
    }
    
    /**
     * Returns the bundle's container extension.
     *
     * @throws \LogicException
     */
    public function getContainerExtension() : ?ExtensionInterface {
        if (!isset($this->extension)) {
            $extension = $this->createContainerExtension();
            if (null !== $extension) {
                if (!$extension instanceof ExtensionInterface) {
                    throw new \LogicException(\sprintf('Extension "%s" must implement Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface.', get_debug_type($extension)));
                }
                // check naming convention
                $basename = preg_replace('/Bundle$/', '', $this->getName());
                $expectedAlias = Container::underscore($basename);
                if ($expectedAlias != $extension->getAlias()) {
                    throw new \LogicException(\sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension->getAlias()));
                }
                $this->extension = $extension;
            }
            else {
                $this->extension = false;
            }
        }
        return $this->extension ?: null;
    }
    public function getNamespace() : string {
        if (!isset($this->namespace)) {
            $this->parseClassName();
        }
        return $this->namespace;
    }
    public function getPath() : string {
        if (!isset($this->path)) {
            $reflected = new \ReflectionObject($this);
            $this->path = \dirname($reflected->getFileName());
        }
        return $this->path;
    }
    
    /**
     * Returns the bundle name (the class short name).
     */
    public final function getName() : string {
        if (!isset($this->name)) {
            $this->parseClassName();
        }
        return $this->name;
    }
    
    /**
     * @return void
     */
    public function registerCommands(Application $application) {
    }
    
    /**
     * Returns the bundle's container extension class.
     */
    protected function getContainerExtensionClass() : string {
        $basename = preg_replace('/Bundle$/', '', $this->getName());
        return $this->getNamespace() . '\\DependencyInjection\\' . $basename . 'Extension';
    }
    
    /**
     * Creates the bundle's container extension.
     */
    protected function createContainerExtension() : ?ExtensionInterface {
        return class_exists($class = $this->getContainerExtensionClass()) ? new $class() : null;
    }
    private function parseClassName() : void {
        $pos = strrpos(static::class, '\\');
        $this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
        $this->name ??= false === $pos ? static::class : substr(static::class, $pos + 1);
    }
    public function setContainer(?ContainerInterface $container) : void {
        $this->container = $container;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Bundle::$container protected property
Bundle::$extension protected property
Bundle::$name protected property
Bundle::$namespace private property
Bundle::$path protected property
Bundle::boot public function Overrides BundleInterface::boot
Bundle::build public function This method can be overridden to register compilation passes,
other extensions, ...
Overrides BundleInterface::build
Bundle::createContainerExtension protected function Creates the bundle&#039;s container extension.
Bundle::getContainerExtension public function Returns the bundle&#039;s container extension. Overrides BundleInterface::getContainerExtension 1
Bundle::getContainerExtensionClass protected function Returns the bundle&#039;s container extension class.
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::getPath public function Gets the Bundle directory path. Overrides BundleInterface::getPath 1
Bundle::parseClassName private function
Bundle::registerCommands public function
Bundle::setContainer public function Overrides BundleInterface::setContainer
Bundle::shutdown public function Overrides BundleInterface::shutdown

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal