Some identation and documentation

This commit is contained in:
2026-08-19 10:55:16 -03:00
parent c2f00d6c21
commit bd2f3bddff
+65 -17
View File
@@ -3,29 +3,72 @@
namespace ORM;
/**
* \PDO generator class
*
* This code is based on the TConnection.php class on the Adianti Framework
*
* @license http://www.adianti.com.br/framework-license
*
*/
* \PDO generator class
*
* This code is based on the TConnection.php class on the Adianti Framework
*
* @license http://www.adianti.com.br/framework-license
*
*/
class Connection {
class Connection
{
private function __construct() {
/**
* Available Database Drivers
* @var array
*/
const array drivers = ["pgsql", "mysql", "sqlite", "ibase", "oci8", "mssq"];
/**
* Private constructor
* This class will not exist, it only encapsulate logic
*/
private function __construct(){ }
/**
* Open a new connection
*
* You need to pass a connection configuration in a Object/Array
*
* user
* pass
* name
* host
* driver
* - pgsql (Postgres)
* - mysql (MySQL)
* - sqlite (SQLite)
* - ibase (Firebird)
* - oci8 (Oracle)
* - mssql SQLServer
* port
* prefix
*
* @param mixed $connectionInfo
*
* @return \PDO
*/
public static function open(mixed $connectionInfo = []): \PDO
{
if (is_array($connectionInfo)) {
$connectionInfo = (object) $connectionInfo;
}
public static function open($connection_info = null) {
if(!isset($connectionInfo->driver)){
throw new \Exception("Driver not defined");
}
$user = isset($connection_info['user']) ? $connection_info['user'] : NULL;
$pass = isset($connection_info['pass']) ? $connection_info['pass'] : NULL;
$name = isset($connection_info['name']) ? $connection_info['name'] : NULL;
$host = isset($connection_info['host']) ? $connection_info['host'] : NULL;
$driver = isset($connection_info['driver']) ? $connection_info['driver'] : NULL;
$port = isset($connection_info['port']) ? $connection_info['port'] : NULL;
$prefix = isset($connection_info['prefix']) ? $connection_info['prefix'] : '';
$user = isset($connectionInfo->user) ? $connectionInfo->user : NULL;
$pass = isset($connectionInfo->pass) ? $connectionInfo->pass : NULL;
$name = isset($connectionInfo->name) ? $connectionInfo->name : NULL;
$host = isset($connectionInfo->host) ? $connectionInfo->host : NULL;
$driver = isset($connectionInfo->driver) ? $connectionInfo->driver : NULL;
$port = isset($connectionInfo->port) ? $connectionInfo->port : NULL;
$prefix = isset($connectionInfo->prefix) ? $connectionInfo->prefix : '';
$traceSQL = isset($connectionInfo->traceSQL) ? $connectionInfo->traceSQL : false;
switch ($driver) {
case 'pgsql':
@@ -49,8 +92,13 @@ class Connection {
$conn = new \PDO("mssql:host={$host},1433;dbname={$name}", $user, $pass);
break;
}
$conn->prefix = $prefix;
$conn->driver = $driver;
$conn->traceSQL = $traceSQL;
$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $conn;
}