function SessionHandler::doWrite
File
-
core/
lib/ Drupal/ Core/ Session/ SessionHandler.php, line 66
Class
- SessionHandler
- Default session handler.
Namespace
Drupal\Core\SessionCode
public function doWrite(string $sessionId, string $data) : bool {
$try_again = FALSE;
$request = $this->requestStack
->getCurrentRequest();
$fields = [
'uid' => $request->getSession()
->get('uid', 0),
'hostname' => $request->getClientIP(),
'session' => $data,
'timestamp' => $this->time
->getRequestTime(),
];
$doWrite = fn() => $this->connection
->merge('sessions')
->keys([
'sid' => Crypt::hashBase64($sessionId),
])
->fields($fields)
->execute();
try {
$doWrite();
} catch (\Exception $e) {
// If there was an exception, try to create the table.
if (!($try_again = $this->ensureTableExists())) {
// If the exception happened for other reason than the missing
// table, propagate the exception.
throw $e;
}
}
// Now that the bin has been created, try again if necessary.
if ($try_again) {
$doWrite();
}
return TRUE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.