From 1fbb0404f54d8e8a56378ae9d957a2982b3d7194 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 17 Jul 2013 20:37:38 -0700 Subject: [PATCH] Allow for IDatabase to be used as type hints for DatabaseBase|DBConnRef * Use this in LogEntry to avoid needless type errors Change-Id: I8644b35b0d9cd171243dd28de52e94ef39d361a7 --- includes/AutoLoader.php | 1 + includes/db/Database.php | 8 +++++++- includes/db/LoadBalancer.php | 2 +- includes/logging/LogEntry.php | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 2f0ac23c51..0950e5f638 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -486,6 +486,7 @@ $wgAutoloadLocalClasses = array( 'DBConnRef' => 'includes/db/LoadBalancer.php', 'DBError' => 'includes/db/DatabaseError.php', 'DBObject' => 'includes/db/DatabaseUtility.php', + 'IDatabase' => 'includes/db/Database.php', 'IORMRow' => 'includes/db/IORMRow.php', 'IORMTable' => 'includes/db/IORMTable.php', 'DBMasterPos' => 'includes/db/DatabaseUtility.php', diff --git a/includes/db/Database.php b/includes/db/Database.php index a86d6be981..04f1f97f56 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -204,11 +204,17 @@ interface DatabaseType { function getServerInfo(); } +/** + * Interface for classes that implement or wrap DatabaseBase + * @ingroup Database + */ +interface IDatabase {} + /** * Database abstraction object * @ingroup Database */ -abstract class DatabaseBase implements DatabaseType { +abstract class DatabaseBase implements IDatabase, DatabaseType { /** Number of times to re-try an operation in case of deadlock */ const DEADLOCK_TRIES = 4; /** Minimum time to wait before retry, in microseconds */ diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index ab200b4a9a..5c4443da9d 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -1091,7 +1091,7 @@ class LoadBalancer { * @ingroup Database * @since 1.22 */ -class DBConnRef { +class DBConnRef implements IDatabase { /** @var LoadBalancer */ protected $lb; /** @var DatabaseBase */ diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index fee4fab6e0..16b72ea63c 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -442,10 +442,10 @@ class ManualLogEntry extends LogEntryBase { /** * Inserts the entry into the logging table. - * @param DatabaseBase $dbw + * @param IDatabase $dbw * @return int If of the log entry */ - public function insert( DatabaseBase $dbw = null ) { + public function insert( IDatabase $dbw = null ) { global $wgContLang; $dbw = $dbw ?: wfGetDB( DB_MASTER ); -- 2.20.1