<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
namespace Friendica\Core\Session\Handler;
-use Friendica\Core\Session;
use Friendica\Database\Database as DBA;
use Psr\Log\LoggerInterface;
-use SessionHandlerInterface;
/**
* SessionHandler using database
*/
-class Database implements SessionHandlerInterface
+class Database extends AbstractSessionHandler
{
/** @var DBA */
private $dba;
private $logger;
/** @var array The $_SERVER variable */
private $server;
+ /** @var bool global check, if the current Session exists */
+ private $sessionExists = false;
/**
* DatabaseSessionHandler constructor.
try {
$session = $this->dba->selectFirst('session', ['data'], ['sid' => $id]);
if ($this->dba->isResult($session)) {
- Session::$exists = true;
+ $this->sessionExists = true;
return $session['data'];
}
} catch (\Exception $exception) {
- $this->logger->warning('Cannot read session.'. ['id' => $id, 'exception' => $exception]);
+ $this->logger->warning('Cannot read session.', ['id' => $id, 'exception' => $exception]);
return '';
}
return $this->destroy($id);
}
- $expire = time() + Session::$expire;
+ $expire = time() + static::EXPIRE;
$default_expire = time() + 300;
try {
- if (Session::$exists) {
+ if ($this->sessionExists) {
$fields = ['data' => $data, 'expire' => $expire];
$condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $id, $data, $expire];
$this->dba->update('session', $fields, $condition);
$this->dba->insert('session', $fields);
}
} catch (\Exception $exception) {
- $this->logger->warning('Cannot write session.'. ['id' => $id, 'exception' => $exception]);
+ $this->logger->warning('Cannot write session.', ['id' => $id, 'exception' => $exception]);
return false;
}
try {
return $this->dba->delete('session', ['sid' => $id]);
} catch (\Exception $exception) {
- $this->logger->warning('Cannot destroy session.'. ['id' => $id, 'exception' => $exception]);
+ $this->logger->warning('Cannot destroy session.', ['id' => $id, 'exception' => $exception]);
return false;
}
}
try {
return $this->dba->delete('session', ["`expire` < ?", time()]);
} catch (\Exception $exception) {
- $this->logger->warning('Cannot use garbage collector.'. ['exception' => $exception]);
+ $this->logger->warning('Cannot use garbage collector.', ['exception' => $exception]);
return false;
}
}