Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NativeSessionStorage.php

function NativeSessionStorage::save

Overrides SessionStorageInterface::save

3 calls to NativeSessionStorage::save()
NativeSessionStorage::regenerate in vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php
Regenerates id that represents this storage.
SessionManager::save in core/lib/Drupal/Core/Session/SessionManager.php
Force the session to be saved and closed.
SessionManager::save in core/lib/Drupal/Core/Session/SessionManager.php
Force the session to be saved and closed.
1 method overrides NativeSessionStorage::save()
SessionManager::save in core/lib/Drupal/Core/Session/SessionManager.php
Force the session to be saved and closed.

File

vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php, line 211

Class

NativeSessionStorage
This provides a base class for session attribute storage.

Namespace

Symfony\Component\HttpFoundation\Session\Storage

Code

public function save() : void {
    // Store a copy so we can restore the bags in case the session was not left empty
    $session = $_SESSION;
    foreach ($this->bags as $bag) {
        if (empty($_SESSION[$key = $bag->getStorageKey()])) {
            unset($_SESSION[$key]);
        }
    }
    if ($_SESSION && [
        $key = $this->metadataBag
            ->getStorageKey(),
    ] === array_keys($_SESSION)) {
        unset($_SESSION[$key]);
    }
    // Register error handler to add information about the current save handler
    $previousHandler = set_error_handler(function ($type, $msg, $file, $line) use (&$previousHandler) {
        if (\E_WARNING === $type && str_starts_with($msg, 'session_write_close():')) {
            $handler = $this->saveHandler instanceof SessionHandlerProxy ? $this->saveHandler
                ->getHandler() : $this->saveHandler;
            $msg = \sprintf('session_write_close(): Failed to write session data with "%s" handler', $handler::class);
        }
        return $previousHandler ? $previousHandler($type, $msg, $file, $line) : false;
    });
    try {
        session_write_close();
    } finally {
        restore_error_handler();
        // Restore only if not empty
        if ($_SESSION) {
            $_SESSION = $session;
        }
    }
    $this->closed = true;
    $this->started = false;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal