From 521e73662d84686c96ae0f0bb83e8970e9adf0b0 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 28 Aug 2018 22:03:40 +0200 Subject: [PATCH] Allow for specification of database name, schema or other qualifier --- src/Administration.php | 5 +++-- src/Auth.php | 7 ++++--- src/UserManager.php | 6 +++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Administration.php b/src/Administration.php index e85dda9..5e97b38 100644 --- a/src/Administration.php +++ b/src/Administration.php @@ -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); } /** diff --git a/src/Auth.php b/src/Auth.php index 880c511..41a1410 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -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); } /** diff --git a/src/UserManager.php b/src/UserManager.php index 9e112ba..b8a8732 100644 --- a/src/UserManager.php +++ b/src/UserManager.php @@ -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; }