function drupal_container

Retrieves the Drupal Container to standardize object construction.

The container is built by the kernel and passed in to this function which stores it statically. The container always contains the services from \Drupal\Core\CoreBundle, the bundles of enabled modules and any other bundles defined in $GLOBALS['conf']['container_bundles'].

Parameters

Symfony\Component\DependencyInjection\Container $new_container: (optional) A new container instance to replace the current.

Return value

Symfony\Component\DependencyInjection\Container|bool The instance of the Container used to set up and maintain object instances or FALSE if none exist yet.

See also

Drupal\Core\DrupalKernel

10 calls to drupal_container()
DrupalKernel::initializeContainer in drupal/core/lib/Drupal/Core/DrupalKernel.php
Initializes the service container.
DrupalUnitTestBase::setUp in drupal/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
Sets up Drupal unit test environment.
drupal_get_js in drupal/core/includes/common.inc
Returns a themed presentation of all JavaScript code for the current page.
install_begin_request in drupal/core/includes/install.core.inc
Begins an installation request, modifying the installation state as needed.
PluginInstanceTest::testPluginInstances in drupal/core/modules/views/lib/Drupal/views/Tests/PluginInstanceTest.php
Tests creating instances of every views plugin.

... See full list

File

drupal/core/includes/bootstrap.inc, line 2452
Functions that need to be loaded on every Drupal request.

Code

function drupal_container(Container $new_container = NULL) {

  // We do not use drupal_static() here because we do not have a mechanism by
  // which to reinitialize the stored objects, so a drupal_static_reset() call
  // would leave Drupal in a nonfunctional state.
  static $container;
  if (isset($new_container)) {
    $container = $new_container;
  }
  return $container;
}