This commit is contained in:
2024-07-29 22:06:57 +02:00
parent 5ce2215e44
commit 6a62ae58fc
22 changed files with 670 additions and 7 deletions
+18
View File
@@ -6,25 +6,43 @@ use PDO;
use Khofmann\Config\Config;
use Exception;
/**
* Facade for database access
*/
class Database extends PDO
{
// Instances array to ensure singleton pattern
private static array $instances = [];
/**
* Private since singleton pattern.
*/
private function __construct(string $dsn, string $username = null, string $password = null, array $options = null)
{
parent::__construct($dsn, $username, $password, $options);
}
/**
* Disallow clone
*/
private function __clone()
{
throw new Exception("Cannot clone a singleton.");
}
/**
* Disallow wakeup
*/
private function __wakeup()
{
throw new Exception("Cannot unserialize a singleton.");
}
/**
* Get the instance. Ensures singleton pattern.
*
* Loads configuration from `Config` facade
*/
public static function getInstance(): Database
{
$cls = static::class;