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");
}