do not use app container in classes
soko-web/pipeline/pr-master This commit looks good

This commit is contained in:
bence committed 2023-04-19 23:26:24 +02:00
1 parent 0f87a9c6e3
commit 4fe463fcc5
9 files changed
+68 -31

No files matched your search

+17 -4
View File
@@ -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();