Merge "Avoid interacting with LBFactory singleton in tests"
[lhc/web/wiklou.git] / includes / db / LBFactory.php
index 6e377ff..847e173 100644 (file)
  * @ingroup Database
  */
 abstract class LBFactory {
-       /**
-        * @var LBFactory
-        */
-       static $instance;
+       /** @var LBFactory */
+       protected static $instance;
 
        /**
         * Disables all access to the load balancer, will cause all database access
@@ -37,7 +35,7 @@ abstract class LBFactory {
         */
        public static function disableBackend() {
                global $wgLBFactoryConf;
-               self::$instance = new LBFactory_Fake( $wgLBFactoryConf );
+               self::$instance = new LBFactoryFake( $wgLBFactoryConf );
        }
 
        /**
@@ -46,15 +44,47 @@ abstract class LBFactory {
         * @return LBFactory
         */
        static function &singleton() {
+               global $wgLBFactoryConf;
+
                if ( is_null( self::$instance ) ) {
-                       global $wgLBFactoryConf;
-                       $class = $wgLBFactoryConf['class'];
+                       $class = self::getLBFactoryClass( $wgLBFactoryConf );
+
                        self::$instance = new $class( $wgLBFactoryConf );
                }
 
                return self::$instance;
        }
 
+       /**
+        * Returns the LBFactory class to use and the load balancer configuration.
+        *
+        * @param array $config (e.g. $wgLBFactoryConf)
+        *
+        * @return string class name
+        */
+       public static function getLBFactoryClass( array $config ) {
+               // For configuration backward compatibility after removing
+               // underscores from class names in MediaWiki 1.23.
+               $bcClasses = array(
+                       'LBFactory_Simple' => 'LBFactorySimple',
+                       'LBFactory_Single' => 'LBFactorySingle',
+                       'LBFactory_Multi' => 'LBFactoryMulti',
+                       'LBFactory_Fake' => 'LBFactoryFake',
+               );
+
+               $class = $config['class'];
+
+               if ( isset( $bcClasses[$class] ) ) {
+                       $class = $bcClasses[$class];
+                       wfDeprecated(
+                               '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
+                               '1.23'
+                       );
+               }
+
+               return $class;
+       }
+
        /**
         * Shut down, close connections and destroy the cached instance.
         */
@@ -167,16 +197,15 @@ abstract class LBFactory {
 /**
  * A simple single-master LBFactory that gets its configuration from the b/c globals
  */
-class LBFactory_Simple extends LBFactory {
+class LBFactorySimple extends LBFactory {
+       /** @var LoadBalancer */
+       protected $mainLB;
 
-       /**
-        * @var LoadBalancer
-        */
-       var $mainLB;
-       var $extLBs = array();
+       /** @var LoadBalancer[] */
+       protected $extLBs = array();
 
-       # Chronology protector
-       var $chronProt;
+       /** @var ChronologyProtector */
+       protected $chronProt;
 
        function __construct( $conf ) {
                $this->chronProt = new ChronologyProtector;
@@ -299,7 +328,7 @@ class LBFactory_Simple extends LBFactory {
  * Call LBFactory::disableBackend() to start using this, and
  * LBFactory::enableBackend() to return to normal behavior
  */
-class LBFactory_Fake extends LBFactory {
+class LBFactoryFake extends LBFactory {
        function __construct( $conf ) {
        }