1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-07-11 11:36:24 +02:00

Allow for specification of database name, schema or other qualifier

This commit is contained in:
Marco
2018-08-28 22:03:40 +02:00
parent 2b3bf611e2
commit 521e73662d
3 changed files with 12 additions and 6 deletions

View File

@ -20,9 +20,10 @@ final class Administration extends UserManager {
/**
* @param PdoDatabase|PdoDsn|\PDO $databaseConnection the database connection to operate on
* @param string|null $dbTablePrefix (optional) the prefix for the names of all database tables used by this component
* @param string|null $dbSchema (optional) the schema name for all database tables used by this component
*/
public function __construct($databaseConnection, $dbTablePrefix = null) {
parent::__construct($databaseConnection, $dbTablePrefix);
public function __construct($databaseConnection, $dbTablePrefix = null, $dbSchema = null) {
parent::__construct($databaseConnection, $dbTablePrefix, $dbSchema);
}
/**

View File

@ -39,9 +39,10 @@ final class Auth extends UserManager {
* @param string|null $dbTablePrefix (optional) the prefix for the names of all database tables used by this component
* @param bool|null $throttling (optional) whether throttling should be enabled (e.g. in production) or disabled (e.g. during development)
* @param int|null $sessionResyncInterval (optional) the interval in seconds after which to resynchronize the session data with its authoritative source in the database
* @param string|null $dbSchema (optional) the schema name for all database tables used by this component
*/
public function __construct($databaseConnection, $ipAddress = null, $dbTablePrefix = null, $throttling = null, $sessionResyncInterval = null) {
parent::__construct($databaseConnection, $dbTablePrefix);
public function __construct($databaseConnection, $ipAddress = null, $dbTablePrefix = null, $throttling = null, $sessionResyncInterval = null, $dbSchema = null) {
parent::__construct($databaseConnection, $dbTablePrefix, $dbSchema);
$this->ipAddress = !empty($ipAddress) ? $ipAddress : (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null);
$this->throttling = isset($throttling) ? (bool) $throttling : true;
@ -1772,7 +1773,7 @@ final class Auth extends UserManager {
* @return Administration
*/
public function admin() {
return new Administration($this->db, $this->dbTablePrefix);
return new Administration($this->db, $this->dbTablePrefix, $this->dbSchema);
}
/**

View File

@ -45,6 +45,8 @@ abstract class UserManager {
/** @var PdoDatabase the database connection to operate on */
protected $db;
/** @var string|null the schema name for all database tables used by this component */
protected $dbSchema;
/** @var string the prefix for the names of all database tables used by this component */
protected $dbTablePrefix;
@ -70,8 +72,9 @@ abstract class UserManager {
/**
* @param PdoDatabase|PdoDsn|\PDO $databaseConnection the database connection to operate on
* @param string|null $dbTablePrefix (optional) the prefix for the names of all database tables used by this component
* @param string|null $dbSchema (optional) the schema name for all database tables used by this component
*/
protected function __construct($databaseConnection, $dbTablePrefix = null) {
protected function __construct($databaseConnection, $dbTablePrefix = null, $dbSchema = null) {
if ($databaseConnection instanceof PdoDatabase) {
$this->db = $databaseConnection;
}
@ -87,6 +90,7 @@ abstract class UserManager {
throw new \InvalidArgumentException('The database connection must be an instance of either `PdoDatabase`, `PdoDsn` or `PDO`');
}
$this->dbSchema = $dbSchema !== null ? (string) $dbSchema : null;
$this->dbTablePrefix = (string) $dbTablePrefix;
}