Merge "Avoid interacting with LBFactory singleton in tests"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 2 Jan 2014 19:54:34 +0000 (19:54 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 2 Jan 2014 19:54:34 +0000 (19:54 +0000)
1  2 
includes/db/LBFactory.php

   * @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
         * @return LBFactory
         */
        static function &singleton() {
+               global $wgLBFactoryConf;
                if ( is_null( self::$instance ) ) {
-                       $LBFactoryConf = self::getLBFactoryClass();
+                       $class = self::getLBFactoryClass( $wgLBFactoryConf );
  
-                       self::$instance = new $LBFactoryConf[0]( $LBFactoryConf[1] );
+                       self::$instance = new $class( $wgLBFactoryConf );
                }
  
                return self::$instance;
        /**
         * Returns the LBFactory class to use and the load balancer configuration.
         *
-        * @return array ( factory class, $wgLBFactoryConf )
+        * @param array $config (e.g. $wgLBFactoryConf)
+        *
+        * @return string class name
         */
-       static function getLBFactoryClass() {
-               global $wgLBFactoryConf;
+       public static function getLBFactoryClass( array $config ) {
                // For configuration backward compatibility after removing
                // underscores from class names in MediaWiki 1.23.
                $bcClasses = array(
@@@ -70,9 -74,9 +72,9 @@@
                        'LBFactory_Fake' => 'LBFactoryFake',
                );
  
-               $class = $wgLBFactoryConf['class'];
+               $class = $config['class'];
  
-               if ( in_array( $class, array_keys( $bcClasses ) ) ) {
+               if ( isset( $bcClasses[$class] ) ) {
                        $class = $bcClasses[$class];
                        wfDeprecated(
                                '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
@@@ -80,7 -84,7 +82,7 @@@
                        );
                }
  
-               return array( $class, $wgLBFactoryConf );
+               return $class;
        }
  
        /**
   * A simple single-master LBFactory that gets its configuration from the b/c globals
   */
  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;