mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-10-23 20:06:05 +02:00
Let parent class 'UserManager' manage database connection for 'Auth'
This commit is contained in:
@@ -8,5 +8,33 @@
|
||||
|
||||
namespace Delight\Auth;
|
||||
|
||||
use Delight\Db\PdoDatabase;
|
||||
use Delight\Db\PdoDsn;
|
||||
|
||||
/** Abstract base class for components implementing user management */
|
||||
abstract class UserManager {}
|
||||
abstract class UserManager {
|
||||
|
||||
/** @var PdoDatabase the database connection to operate on */
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @param PdoDatabase|PdoDsn|\PDO $databaseConnection the database connection to operate on
|
||||
*/
|
||||
protected function __construct($databaseConnection) {
|
||||
if ($databaseConnection instanceof PdoDatabase) {
|
||||
$this->db = $databaseConnection;
|
||||
}
|
||||
elseif ($databaseConnection instanceof PdoDsn) {
|
||||
$this->db = PdoDatabase::fromDsn($databaseConnection);
|
||||
}
|
||||
elseif ($databaseConnection instanceof \PDO) {
|
||||
$this->db = PdoDatabase::fromPdo($databaseConnection, true);
|
||||
}
|
||||
else {
|
||||
$this->db = null;
|
||||
|
||||
throw new \InvalidArgumentException('The database connection must be an instance of either `PdoDatabase`, `PdoDsn` or `PDO`');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user