You are here

public static function ServiceContainer::init in Service Container 7.2

Same name and namespace in other branches
  1. 7 lib/ServiceContainer.php \ServiceContainer::init()

Initializes the container.

This can be safely called from hook_boot() because the container will only be build if we have reached the DRUPAL_BOOTSTRAP_FULL phase.

Return value

bool TRUE when the container was initialized, FALSE otherwise.

5 calls to ServiceContainer::init()
DatabaseStorageExpirableTest::setUp in lib/Drupal/service_container/Tests/KeyValue/DatabaseStorageExpirableTest.php
MemoryStorageTest::setUp in lib/Drupal/service_container/Tests/KeyValue/MemoryStorageTest.php
ServiceContainerIntegrationTestBase::setUp in lib/Drupal/service_container/Tests/ServiceContainerIntegrationTestBase.php
service_container_modules_enabled in ./service_container.module
Implements hook_modules_enabled().
service_container_stream_wrappers_alter in ./service_container.module
Implements hook_stream_wrappers_alter().

File

lib/ServiceContainer.php, line 24
Contains ServiceContainer

Class

ServiceContainer
Static Service Container wrapper extension - initializes the container.

Code

public static function init() {

  // If this is set already, just return.
  if (isset(static::$container)) {
    return TRUE;
  }
  $container_builder = static::getContainerBuilder();
  if ($container_builder
    ->isCached()) {
    static::$container = $container_builder
      ->compile();
    static::dispatchStaticEvent('containerReady', array(
      static::$container,
    ));
    return TRUE;
  }

  // If we have not yet fully bootstrapped, we can't build the container.
  if (drupal_bootstrap(NULL, FALSE) != DRUPAL_BOOTSTRAP_FULL) {
    return FALSE;
  }

  // Rebuild the container.
  static::$container = $container_builder
    ->compile();
  static::dispatchStaticEvent('containerReady', array(
    static::$container,
  ));
  return (bool) static::$container;
}