This commit is contained in:
9 files changed
+68
-31
No files matched your search
@@ -3,11 +3,24 @@
|
||||
use Generator;
|
||||
use SokoWeb\Database\Query\Modify;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
use SokoWeb\Interfaces\Database\IConnection;
|
||||
use SokoWeb\Interfaces\Database\IAuditLogger;
|
||||
use SokoWeb\Interfaces\Database\IResultSet;
|
||||
use SokoWeb\Interfaces\PersistentData\IPersistentDataManager;
|
||||
use SokoWeb\PersistentData\Model\Model;
|
||||
|
||||
class PersistentDataManager
|
||||
class PersistentDataManager implements IPersistentDataManager
|
||||
{
|
||||
private IConnection $dbConnection;
|
||||
|
||||
private IAuditLogger $auditLogger;
|
||||
|
||||
public function __construct(IConnection $dbConnection, IAuditLogger $auditLogger)
|
||||
{
|
||||
$this->dbConnection = $dbConnection;
|
||||
$this->auditLogger = $auditLogger;
|
||||
}
|
||||
|
||||
public function selectFromDb(Select $select, string $type, bool $useRelations = false, array $withRelations = [])
|
||||
{
|
||||
$select = $this->createSelect($select, $type, $useRelations, $withRelations);
|
||||
@@ -39,7 +52,7 @@ class PersistentDataManager
|
||||
|
||||
public function selectFromDbById($id, string $type, bool $useRelations = false)
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select = new Select($this->dbConnection);
|
||||
$select->whereId($id);
|
||||
|
||||
return $this->selectFromDb($select, $type, $useRelations);
|
||||
@@ -117,7 +130,7 @@ class PersistentDataManager
|
||||
$modified = $model->toArray();
|
||||
$id = $model->getId();
|
||||
|
||||
$modify = new Modify(\Container::$dbConnection, $model::getTable(), \Container::$auditLogger);
|
||||
$modify = new Modify($this->dbConnection, $model::getTable(), $this->auditLogger);
|
||||
|
||||
if ($id !== null) {
|
||||
$original = $model->getSnapshot();
|
||||
@@ -149,7 +162,7 @@ class PersistentDataManager
|
||||
|
||||
public function deleteFromDb(Model $model): void
|
||||
{
|
||||
$modify = new Modify(\Container::$dbConnection, $model::getTable(), \Container::$auditLogger);
|
||||
$modify = new Modify($this->dbConnection, $model::getTable(), $this->auditLogger);
|
||||
$modify->setId($model->getId());
|
||||
$modify->fill($model->toArray());
|
||||
$modify->delete();
|
||||
|
||||
Reference in new issue
Block a user