diff --git a/core/lib/Drupal/Core/Session/Session.php b/core/lib/Drupal/Core/Session/Session.php index 65b6ce1..2939cc5 100644 --- a/core/lib/Drupal/Core/Session/Session.php +++ b/core/lib/Drupal/Core/Session/Session.php @@ -44,9 +44,9 @@ class Session { * This value has to persist, since a potentially wrong or disallowed session * would be written otherwise. * - * @var bool + * @var int */ - protected static $enabled = TRUE; + protected static $disableLevel = 0; /** * Whether the session has been started. @@ -110,9 +110,10 @@ public function initialize() { * Starts a session forcefully, preserving already set session data. */ public function start() { - if ($this->isCli() || $this->isStarted()) { + if ($this->isCli() || $this->isAnyActive()) { return; } + // Save current session data before starting it, as PHP will destroy it. $session_data = isset($_SESSION) ? $_SESSION : NULL; @@ -164,10 +165,17 @@ public function save() { } /** - * Returns whether a session has been started. + * Returns whether this session has been started. */ public function isStarted() { - return $this->started && session_status() === \PHP_SESSION_ACTIVE; + return $this->started && $this->isAnyActive(); + } + + /** + * Returns whether any PHP session is active. + */ + public function isAnyActive() { + return session_status() === \PHP_SESSION_ACTIVE; } /** @@ -249,7 +257,7 @@ public function migrate() { * FALSE if writing session data has been disabled. TRUE otherwise. */ public function isEnabled() { - return static::$enabled; + return static::$disableLevel == 0; } /** @@ -264,7 +272,7 @@ public function isEnabled() { * @return $this */ public function disable() { - static::$enabled = FALSE; + static::$disableLevel++; return $this; } @@ -274,7 +282,9 @@ public function disable() { * @return $this */ public function enable() { - static::$enabled = TRUE; + if (static::$disableLevel > 0) { + static::$disableLevel--; + } return $this; }