1
0
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:
Marco
2017-02-21 08:40:30 +01:00
parent 6a15679238
commit 9252bee030
2 changed files with 31 additions and 16 deletions

View File

@@ -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`');
}
}
}