* @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.
*/
/**
* Set the instance to be the given object
*
- * @param $instance LBFactory
+ * @param LBFactory $instance
*/
static function setInstance( $instance ) {
self::destroyInstance();
/**
* Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
- * @param $conf
+ * @param array $conf
*/
abstract function __construct( $conf );
* Create a new load balancer object. The resulting object will be untracked,
* not chronology-protected, and the caller is responsible for cleaning it up.
*
- * @param string $wiki wiki ID, or false for the current wiki
+ * @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
abstract function newMainLB( $wiki = false );
/**
* Get a cached (tracked) load balancer object.
*
- * @param string $wiki wiki ID, or false for the current wiki
+ * @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
abstract function getMainLB( $wiki = false );
* untracked, not chronology-protected, and the caller is responsible for
* cleaning it up.
*
- * @param string $cluster external storage cluster, or false for core
- * @param string $wiki wiki ID, or false for the current wiki
- *
+ * @param string $cluster External storage cluster, or false for core
+ * @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
abstract function newExternalLB( $cluster, $wiki = false );
* Get a cached (tracked) load balancer for external storage
*
* @param string $cluster external storage cluster, or false for core
- * @param string $wiki wiki ID, or false for the current wiki
- *
+ * @param bool|string $wiki Wiki ID, or false for the current wiki
* @return LoadBalancer
*/
abstract function &getExternalLB( $cluster, $wiki = false );
* Execute a function for each tracked load balancer
* The callback is called with the load balancer as the first parameter,
* and $params passed as the subsequent parameters.
- * @param $callback string|array
+ *
+ * @param callable $callback
* @param array $params
*/
abstract function forEachLB( $callback, $params = array() );
/**
* Call a method of each tracked load balancer
- * @param $methodName string
- * @param $args array
+ *
+ * @param string $methodName
+ * @param array $args
*/
function forEachLBCallMethod( $methodName, $args = array() ) {
$this->forEachLB( array( $this, 'callMethod' ), array( $methodName, $args ) );
/**
* Private helper for forEachLBCallMethod
- * @param $loadBalancer
- * @param $methodName string
+ * @param LoadBalancer $loadBalancer
+ * @param string $methodName
* @param $args
*/
function callMethod( $loadBalancer, $methodName, $args ) {
/**
* 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;
}
/**
- * @param $wiki
+ * @param bool|string $wiki
* @return LoadBalancer
*/
function newMainLB( $wiki = false ) {
}
/**
- * @param $wiki
+ * @param bool|string $wiki
* @return LoadBalancer
*/
function getMainLB( $wiki = false ) {
/**
* @throws MWException
- * @param $cluster
- * @param $wiki
+ * @param string $cluster
+ * @param bool|string $wiki
* @return LoadBalancer
*/
function newExternalLB( $cluster, $wiki = false ) {
}
/**
- * @param $cluster
- * @param $wiki
+ * @param string $cluster
+ * @param bool|string $wiki
* @return array
*/
function &getExternalLB( $cluster, $wiki = false ) {
* Execute a function for each tracked load balancer
* The callback is called with the load balancer as the first parameter,
* and $params passed as the subsequent parameters.
- * @param $callback
- * @param $params array
+ *
+ * @param callable $callback
+ * @param array $params
*/
function forEachLB( $callback, $params = array() ) {
if ( isset( $this->mainLB ) ) {
* 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 ) {
}