* @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(
'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',
);
}
- 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;