diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 6a99528..25773bf 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -734,7 +734,7 @@ function drupal_bootstrap($phase = NULL) { $boot_level = $phase; } - return \Drupal::getContainer() ? DRUPAL_BOOTSTRAP_CODE : DRUPAL_BOOTSTRAP_CONFIGURATION; + return \Drupal::hasContainer() ? DRUPAL_BOOTSTRAP_CODE : DRUPAL_BOOTSTRAP_CONFIGURATION; } /** diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 127ed77..9c50eb1 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -139,6 +139,16 @@ public static function getContainer($exception_on_invalid = FALSE) { } /** + * Returns TRUE if the container has been initialized, FALSE otherwise. + * + * @return bool + */ + public static function hasContainer() { + return static::$container !== NULL; + } + + + /** * Retrieves a service from the container. * * Use this method if the desired service is not one of those with a dedicated @@ -164,7 +174,7 @@ public static function service($id) { * TRUE if the specified service exists, FALSE otherwise. */ public static function hasService($id) { - return static::getContainer(TRUE)->has($id); + return static::hasContainer() && static::getContainer()->has($id); } /** @@ -183,7 +193,7 @@ public static function root() { * TRUE if there is a currently active request object, FALSE otherwise. */ public static function hasRequest() { - return static::getContainer(TRUE)->has('request_stack') && static::getContainer(TRUE)->get('request_stack')->getCurrentRequest() !== NULL; + return static::hasContainer() && static::getContainer()->has('request_stack') && static::getContainer()->get('request_stack')->getCurrentRequest() !== NULL; } /**