This commit is contained in:
9 files changed
+68
-31
No files matched your search
@@ -3,15 +3,23 @@
|
||||
use DateTime;
|
||||
use SokoWeb\Database\Query\Modify;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
use SokoWeb\Interfaces\Database\IConnection;
|
||||
use SokoWeb\Interfaces\Database\IResultSet;
|
||||
use SokoWeb\Interfaces\Session\ISessionHandler;
|
||||
|
||||
class DatabaseSessionHandler implements ISessionHandler
|
||||
{
|
||||
private IConnection $dbConnection;
|
||||
|
||||
private bool $exists = false;
|
||||
|
||||
private bool $written = false;
|
||||
|
||||
public function __construct(IConnection $dbConnection)
|
||||
{
|
||||
$this->dbConnection = $dbConnection;
|
||||
}
|
||||
|
||||
public function open($savePath, $sessionName): bool
|
||||
{
|
||||
return true;
|
||||
@@ -24,7 +32,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
|
||||
public function read($id): string
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection, 'sessions');
|
||||
$select = new Select($this->dbConnection, 'sessions');
|
||||
$select->columns(['data']);
|
||||
$select->whereId(substr($id, 0, 32));
|
||||
|
||||
@@ -41,7 +49,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
|
||||
public function write($id, $data): bool
|
||||
{
|
||||
$modify = new Modify(\Container::$dbConnection, 'sessions');
|
||||
$modify = new Modify($this->dbConnection, 'sessions');
|
||||
|
||||
if ($this->exists) {
|
||||
$modify->setId(substr($id, 0, 32));
|
||||
@@ -60,7 +68,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
|
||||
public function destroy($id): bool
|
||||
{
|
||||
$modify = new Modify(\Container::$dbConnection, 'sessions');
|
||||
$modify = new Modify($this->dbConnection, 'sessions');
|
||||
$modify->setId(substr($id, 0, 32));
|
||||
$modify->delete();
|
||||
|
||||
@@ -93,7 +101,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
$modify = new Modify(\Container::$dbConnection, 'sessions');
|
||||
$modify = new Modify($this->dbConnection, 'sessions');
|
||||
|
||||
$modify->setId(substr($id, 0, 32));
|
||||
$modify->set('updated', (new DateTime())->format('Y-m-d H:i:s'));
|
||||
|
||||
Reference in new issue
Block a user