requestStack = $request_stack; $this->connection = $connection; } /** * {@inheritdoc} */ public function open($save_path, $name) { return TRUE; } /** * {@inheritdoc} */ public function read($sid) { $data = ''; if (!empty($sid)) { // Read the session data from the database. $query = $this->connection ->queryRange('SELECT session FROM {sessions} WHERE sid = :sid', 0, 1, [':sid' => Crypt::hashBase64($sid)]); $data = (string) $query->fetchField(); } return $data; } /** * {@inheritdoc} */ public function write($sid, $value) { // The exception handler is not active at this point, so we need to do it // manually. try { $request = $this->requestStack->getCurrentRequest(); $fields = [ 'uid' => $request->getSession()->get('uid', 0), 'hostname' => $request->getClientIP(), 'session' => $value, 'timestamp' => REQUEST_TIME, ]; $this->connection->merge('sessions') ->keys(['sid' => Crypt::hashBase64($sid)]) ->fields($fields) ->execute(); return TRUE; } catch (\Exception $exception) { require_once DRUPAL_ROOT . '/core/includes/errors.inc'; // If we are displaying errors, then do so with no possibility of a // further uncaught exception being thrown. if (error_displayable()) { print '
' . Error::renderExceptionSafe($exception) . '