Docs
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user