You are here

public static function Drupal::getContainer in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal.php \Drupal::getContainer()
  2. 9 core/lib/Drupal.php \Drupal::getContainer()

Returns the currently active global container.

Return value

\Symfony\Component\DependencyInjection\ContainerInterface

Throws

\Drupal\Core\DependencyInjection\ContainerNotInitializedException

146 calls to Drupal::getContainer()
BigPipeTestController::test in core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php
Returns all BigPipe placeholder test case render arrays.
BlockUiTest::testBlockPlacementIndicator in core/modules/block/tests/src/Functional/BlockUiTest.php
Tests the block placement indicator.
Cache::getBins in core/lib/Drupal/Core/Cache/Cache.php
Gets all cache bin services.
CKEditor5::validateConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
CKEditor5::validatePair in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Validates a Text Editor + Text Format pair.

... See full list

File

core/lib/Drupal.php, line 157

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;
}