Allow for IDatabase to be used as type hints for DatabaseBase|DBConnRef
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 18 Jul 2013 03:37:38 +0000 (20:37 -0700)
committerTim Starling <tstarling@wikimedia.org>
Thu, 18 Jul 2013 03:43:20 +0000 (03:43 +0000)
* Use this in LogEntry to avoid needless type errors

Change-Id: I8644b35b0d9cd171243dd28de52e94ef39d361a7

includes/AutoLoader.php
includes/db/Database.php
includes/db/LoadBalancer.php
includes/logging/LogEntry.php

index 2f0ac23..0950e5f 100644 (file)
@@ -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',
index a86d6be..04f1f97 100644 (file)
@@ -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 */
index ab200b4..5c4443d 100644 (file)
@@ -1091,7 +1091,7 @@ class LoadBalancer {
  * @ingroup Database
  * @since 1.22
  */
-class DBConnRef {
+class DBConnRef implements IDatabase {
        /** @var LoadBalancer */
        protected $lb;
        /** @var DatabaseBase */
index fee4fab..16b72ea 100644 (file)
@@ -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 );