code beautifier
This commit is contained in:
@@ -30,21 +30,21 @@ class Connection
|
|||||||
if (is_dir($config)) {
|
if (is_dir($config)) {
|
||||||
$this->loadEnv($config);
|
$this->loadEnv($config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->initPdo();
|
$this->initPdo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseArray($config)
|
private function parseArray($config)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$key = (strtolower(trim($this->name)));
|
$key = (strtolower(trim($this->name)));
|
||||||
$this->type = isset($config[$key]["TYPE"]) ? $config[$key]["TYPE"] : null;
|
$this->type = isset($config[$key]["TYPE"]) ? $config[$key]["TYPE"] : null;
|
||||||
$this->user = isset($config[$key]["USER"]) ? $config[$key]["USER"] : null;
|
$this->user = isset($config[$key]["USER"]) ? $config[$key]["USER"] : null;
|
||||||
$this->host = isset($config[$key]["HOST"]) ? $config[$config[$key]["HOST"]] : null;
|
$this->host = isset($config[$key]["HOST"]) ? $config[$config[$key]["HOST"]] : null;
|
||||||
$this->password = isset($config[$key]["PASSWORD"]) ? $config[$key]["PASSWORD"] : null;
|
$this->password = isset($config[$key]["PASSWORD"]) ? $config[$key]["PASSWORD"] : null;
|
||||||
$this->database = isset($config[$key]["DATABASE"]) ? $config[$key]["DATABASE"] : null;
|
$this->database = isset($config[$key]["DATABASE"]) ? $config[$key]["DATABASE"] : null;
|
||||||
$this->port = isset($config[$key]["PORT"]) ? $config[$key]["PORT"] : null;
|
$this->port = isset($config[$key]["PORT"]) ? $config[$key]["PORT"] : null;
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
$this->error = $th->getMessage();
|
$this->error = $th->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,21 +172,20 @@ class Connection
|
|||||||
if (!isset(self::$instances[$connection])) {
|
if (!isset(self::$instances[$connection])) {
|
||||||
self::$instances[$connection] = new Connection($connection, $config);
|
self::$instances[$connection] = new Connection($connection, $config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getInstance($connection="")
|
public static function getInstance($connection = "")
|
||||||
{
|
{
|
||||||
if($connection=="" && count(self::$instances)>0)
|
if ($connection == "" && count(self::$instances) > 0) {
|
||||||
{
|
|
||||||
$connection = array_keys(self::$instances)[0];
|
$connection = array_keys(self::$instances)[0];
|
||||||
}
|
}
|
||||||
if (isset(self::$instances[$connection])) {
|
if (isset(self::$instances[$connection])) {
|
||||||
$instance = self::$instances[$connection];
|
$instance = self::$instances[$connection];
|
||||||
if ($instance instanceof Connection) {
|
if ($instance instanceof Connection) {
|
||||||
return self::$instances[$connection];
|
return self::$instances[$connection];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new \Exception("Unknown connection");
|
throw new \Exception("Unknown connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ class Model
|
|||||||
protected array $updated;
|
protected array $updated;
|
||||||
protected string $table;
|
protected string $table;
|
||||||
protected string $connection = "";
|
protected string $connection = "";
|
||||||
protected string $pk;
|
protected string $pk;
|
||||||
private bool $new;
|
private bool $new;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->new = true;
|
$this->new = true;
|
||||||
$this->values = array();
|
$this->values = array();
|
||||||
$this->updated = array();
|
$this->updated = array();
|
||||||
@@ -62,7 +62,7 @@ class Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function save(): bool
|
public function save(): bool
|
||||||
{
|
{
|
||||||
$ret = false;
|
$ret = false;
|
||||||
$qb = $this->newQueryBuilder();
|
$qb = $this->newQueryBuilder();
|
||||||
if ($this->new) {
|
if ($this->new) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Kletellier\PdoWrapper;
|
namespace Kletellier\PdoWrapper;
|
||||||
|
|
||||||
class QueryBuilder
|
class QueryBuilder
|
||||||
{
|
{
|
||||||
protected array $columns;
|
protected array $columns;
|
||||||
protected array $wheres;
|
protected array $wheres;
|
||||||
protected array $orders;
|
protected array $orders;
|
||||||
@@ -20,7 +20,7 @@ class QueryBuilder
|
|||||||
{
|
{
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
$this->pk = $pk;
|
$this->pk = $pk;
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->reset();
|
$this->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ class QueryBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getData(): mixed
|
private function getData(): mixed
|
||||||
{
|
{
|
||||||
return Connection::getInstance($this->connection)->getSelectQuery($this->getQuery());
|
return Connection::getInstance($this->connection)->getSelectQuery($this->getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user