* @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
*/
public static function disableBackend() {
global $wgLBFactoryConf;
- self::$instance = new LBFactory_Fake( $wgLBFactoryConf );
+ self::$instance = new LBFactoryFake( $wgLBFactoryConf );
}
/**
* @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.
*/
/**
* 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;
* 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 ) {
}