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

Breadcrumb

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

function Drupal::getContainer

Returns the currently active global container.

Return value

\Drupal\Component\DependencyInjection\ContainerInterface

Throws

\Drupal\Core\DependencyInjection\ContainerNotInitializedException

20 calls to Drupal::getContainer()
Cache::getBins in core/lib/Drupal/Core/Cache/Cache.php
Gets all cache bin services.
Cache::getMemoryBins in core/lib/Drupal/Core/Cache/Cache.php
Gets all memory cache bin services.
ConstraintFactory::createInstance in core/lib/Drupal/Core/Validation/ConstraintFactory.php
Creates a plugin instance based on the provided ID and configuration.
ContainerDerivativeDiscoveryDecorator::getDeriver in core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php
Gets a deriver for a base plugin.
ContainerFactory::createInstance in core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php
Creates a plugin instance based on the provided ID and configuration.

... See full list

File

core/lib/Drupal.php, line 167

Class

Drupal
Static Service Container wrapper.

Code

public static function getContainer() {
    if (static::$container === NULL) {
        throw new ContainerNotInitializedException('\\Drupal::$container is not initialized yet. \\Drupal::setContainer() must be called with a real container.');
    }
    return static::$container;
}
RSS feed
Powered by Drupal