code beautifier

This commit is contained in:
Gregory Letellier
2023-11-03 09:01:55 +01:00
parent 4d7f0d6d83
commit 72ba193a1e
3 changed files with 15 additions and 16 deletions

View File

@@ -30,21 +30,21 @@ class Connection
if (is_dir($config)) {
$this->loadEnv($config);
}
}
}
$this->initPdo();
}
private function parseArray($config)
{
try {
$key = (strtolower(trim($this->name)));
$key = (strtolower(trim($this->name)));
$this->type = isset($config[$key]["TYPE"]) ? $config[$key]["TYPE"] : null;
$this->user = isset($config[$key]["USER"]) ? $config[$key]["USER"] : null;
$this->host = isset($config[$key]["HOST"]) ? $config[$config[$key]["HOST"]] : null;
$this->password = isset($config[$key]["PASSWORD"]) ? $config[$key]["PASSWORD"] : null;
$this->database = isset($config[$key]["DATABASE"]) ? $config[$key]["DATABASE"] : null;
$this->port = isset($config[$key]["PORT"]) ? $config[$key]["PORT"] : null;
} catch (\Throwable $th) {
} catch (\Throwable $th) {
$this->error = $th->getMessage();
}
}
@@ -172,21 +172,20 @@ class Connection
if (!isset(self::$instances[$connection])) {
self::$instances[$connection] = new Connection($connection, $config);
}
}
}
}
public static function getInstance($connection="")
{
if($connection=="" && count(self::$instances)>0)
{
public static function getInstance($connection = "")
{
if ($connection == "" && count(self::$instances) > 0) {
$connection = array_keys(self::$instances)[0];
}
}
if (isset(self::$instances[$connection])) {
$instance = self::$instances[$connection];
if ($instance instanceof Connection) {
return self::$instances[$connection];
}
}
}
throw new \Exception("Unknown connection");
}

View File

@@ -8,11 +8,11 @@ class Model
protected array $updated;
protected string $table;
protected string $connection = "";
protected string $pk;
protected string $pk;
private bool $new;
public function __construct()
{
{
$this->new = true;
$this->values = array();
$this->updated = array();
@@ -62,7 +62,7 @@ class Model
}
public function save(): bool
{
{
$ret = false;
$qb = $this->newQueryBuilder();
if ($this->new) {

View File

@@ -3,7 +3,7 @@
namespace Kletellier\PdoWrapper;
class QueryBuilder
{
{
protected array $columns;
protected array $wheres;
protected array $orders;
@@ -20,7 +20,7 @@ class QueryBuilder
{
$this->table = $table;
$this->pk = $pk;
$this->connection = $connection;
$this->connection = $connection;
$this->reset();
}
@@ -194,7 +194,7 @@ class QueryBuilder
}
private function getData(): mixed
{
{
return Connection::getInstance($this->connection)->getSelectQuery($this->getQuery());
}