diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-12-16 07:35:56 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-12-16 07:35:56 +0000 |
| commit | 1cd587fa0413bdbae1fc3bdca10ccc2a1fee7c07 (patch) | |
| tree | 14bafcf0798157baab784b59d22190554e804c18 /lib/session/DbSessionHandler.php | |
| parent | 52e6b5643310ba1f8b2f1f26ac4f2e03d39b476d (diff) | |
fix coding style and some bugs, re #1552
Merge request studip/studip!3764
Diffstat (limited to 'lib/session/DbSessionHandler.php')
| -rw-r--r-- | lib/session/DbSessionHandler.php | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/lib/session/DbSessionHandler.php b/lib/session/DbSessionHandler.php index 05a31a4..d64fe46 100644 --- a/lib/session/DbSessionHandler.php +++ b/lib/session/DbSessionHandler.php @@ -11,70 +11,69 @@ */ namespace Studip\Session; -use \DBManager, \Config, \CronjobTask; +use DBManager; +use Config; +use CronjobTask; +use SessionGcJob; +use SessionHandlerInterface; +use SessionIdInterface; +use SessionUpdateTimestampHandlerInterface; -class DbSessionHandler implements \SessionHandlerInterface, \SessionIdInterface, \SessionUpdateTimestampHandlerInterface +class DbSessionHandler implements + SessionHandlerInterface, + SessionIdInterface, + SessionUpdateTimestampHandlerInterface { + private ?string $exists = null; - private $exists; - - /** - * @inheritDoc - */ public function close(): bool { return true; } - /** - * @inheritDoc - */ - public function destroy($id): bool + public function destroy(string $id): bool { - return (bool)DBManager::get()->execute("DELETE FROM session_data WHERE sid = ? LIMIT 1", [$id]); + return (bool) DBManager::get()->execute( + "DELETE FROM session_data WHERE sid = ? LIMIT 1", + [$id] + ); } - /** - * @inheritDoc - */ - public function gc($max_lifetime): false|int + public function gc(int $max_lifetime): false|int { - //bail out if cronjob activated and not called in cli context - if (Config::getInstance()->getValue('CRONJOBS_ENABLE') - && ($task = array_pop(CronjobTask::findByClass('SessionGcJob'))) + // bail out if cronjob activated and not called in cli context + if ( + Config::getInstance()->getValue('CRONJOBS_ENABLE') + && ($task = CronjobTask::findOneByClass(SessionGcJob::class)) && count($task->schedules->findBy('active', 1)) && PHP_SAPI !== 'cli' ) { return false; } - return DBManager::get()->execute("DELETE FROM session_data WHERE changed < FROM_UNIXTIME(?) ", [time() - $max_lifetime]); + return DBManager::get()->execute( + "DELETE FROM session_data WHERE changed < FROM_UNIXTIME(?) ", + [time() - $max_lifetime] + ); } - /** - * @inheritDoc - */ - public function open($path, $name): bool + public function open(string $path, string $name): bool { return true; } - /** - * @inheritDoc - */ - #[\ReturnTypeWillChange] - public function read($id) + public function read(string $id): false|string { - $str = DBManager::get()->fetchColumn("SELECT val FROM session_data where sid = ?", [$id]); + $str = DBManager::get()->fetchColumn( + "SELECT val FROM session_data where sid = ?", + [$id] + ); if ($str) { $this->exists = $id; } - return (string)$str; + return $str ?: ''; } - /** - * @inheritDoc - */ - public function write($id, $data): bool + public function write(string $id, string $data): bool { $db = DBManager::get(); if ($this->exists === $id) { @@ -85,9 +84,12 @@ class DbSessionHandler implements \SessionHandlerInterface, \SessionIdInterface, return (bool) $stmt->execute([$data, $id]); } - public function exists($id) + public function exists(string $id): bool { - return (bool)DBManager::get()->fetchColumn("SELECT 1 FROM session_data where sid = ?", [$id]); + return (bool) DBManager::get()->fetchColumn( + "SELECT 1 FROM session_data where sid = ?", + [$id] + ); } public function create_sid(): string @@ -107,7 +109,7 @@ class DbSessionHandler implements \SessionHandlerInterface, \SessionIdInterface, public function validateId(string $id): bool { - return (bool)$this->exists($id); + return $this->exists($id); } |
