renommage de l'objet DB en Connection, suppression de la variable privée db dans le model
This commit is contained in:
@@ -6,7 +6,7 @@ use Dotenv\Dotenv;
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
|
||||
class Db
|
||||
class Connection
|
||||
{
|
||||
protected PDO $pdo;
|
||||
protected string $name;
|
||||
@@ -170,7 +170,7 @@ class Db
|
||||
{
|
||||
foreach ($connections as $connection) {
|
||||
if (!isset(self::$instances[$connection])) {
|
||||
self::$instances[$connection] = new Db($connection, $config);
|
||||
self::$instances[$connection] = new Connection($connection, $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ class Db
|
||||
}
|
||||
if (isset(self::$instances[$connection])) {
|
||||
$instance = self::$instances[$connection];
|
||||
if ($instance instanceof Db) {
|
||||
if ($instance instanceof Connection) {
|
||||
return self::$instances[$connection];
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,11 @@ class Model
|
||||
protected array $updated;
|
||||
protected string $table;
|
||||
protected string $connection = "";
|
||||
protected string $pk;
|
||||
private ?Db $db;
|
||||
protected string $pk;
|
||||
private bool $new;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = null;
|
||||
{
|
||||
$this->new = true;
|
||||
$this->values = array();
|
||||
$this->updated = array();
|
||||
@@ -64,13 +62,12 @@ class Model
|
||||
}
|
||||
|
||||
public function save(): bool
|
||||
{
|
||||
$this->db = Db::getInstance($this->connection);
|
||||
{
|
||||
$ret = false;
|
||||
$qb = $this->newQueryBuilder();
|
||||
if ($this->new) {
|
||||
$query = $qb->getPreparedQuery($this->values);
|
||||
$id = $this->db->insertQuery($query);
|
||||
$id = Connection::getInstance($this->connection)->insertQuery($query);
|
||||
if ($id !== false) {
|
||||
$this->values[$this->pk] = $id;
|
||||
$this->new = false;
|
||||
@@ -85,7 +82,7 @@ class Model
|
||||
$data[$updatecol] = $this->values[$updatecol];
|
||||
}
|
||||
$query = $qb->getPreparedQuery($data, false);
|
||||
$ret = $this->db->updateQuery($query);
|
||||
$ret = Connection::getInstance($this->connection)->updateQuery($query);
|
||||
if ($ret) {
|
||||
$this->updated = [];
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Kletellier\PdoWrapper;
|
||||
|
||||
class QueryBuilder
|
||||
{
|
||||
protected ?Db $db;
|
||||
protected ?Connection $db;
|
||||
protected array $columns;
|
||||
protected array $wheres;
|
||||
protected array $orders;
|
||||
@@ -197,7 +197,7 @@ class QueryBuilder
|
||||
|
||||
private function getData(): mixed
|
||||
{
|
||||
$this->db = Db::getInstance($this->connection);
|
||||
$this->db = Connection::getInstance($this->connection);
|
||||
return $this->db->getSelectQuery($this->getQuery());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user