Moar documentations
[lhc/web/wiklou.git] / includes / db / LBFactory.php
index 89a99d0..0ed9224 100644 (file)
  * @ingroup Database
  */
 abstract class LBFactory {
+
+       /**
+        * @var LBFactory
+        */
        static $instance;
 
        /**
@@ -22,16 +26,10 @@ abstract class LBFactory {
                self::$instance = new LBFactory_Fake( $wgLBFactoryConf );
        }
 
-       /**
-        * Resets the singleton for use if it's been disabled. Does nothing otherwise
-        */
-       public static function enableBackend() {
-               if( self::$instance instanceof LBFactory_Fake )
-                       self::$instance = null;
-       }
-
        /**
         * Get an LBFactory instance
+        *
+        * @return LBFactory
         */
        static function &singleton() {
                if ( is_null( self::$instance ) ) {
@@ -54,8 +52,19 @@ abstract class LBFactory {
                }
        }
 
+       /**
+        * Set the instance to be the given object
+        *
+        * @param $instance LBFactory
+        */
+       static function setInstance( $instance ) {
+               self::destroyInstance();
+               self::$instance = $instance;
+       }
+
        /**
         * Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
+        * @param $conf
         */
        abstract function __construct( $conf );
 
@@ -76,21 +85,25 @@ abstract class LBFactory {
         */
        abstract function getMainLB( $wiki = false );
 
-       /*
+       /**
         * Create a new load balancer for external storage. The resulting object will be
         * untracked, not chronology-protected, and the caller is responsible for
         * cleaning it up.
         *
         * @param $cluster String: external storage cluster, or false for core
         * @param $wiki String: 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 $cluster String: external storage cluster, or false for core
         * @param $wiki String: wiki ID, or false for the current wiki
+        *
+        * @return LoadBalancer
         */
        abstract function &getExternalLB( $cluster, $wiki = false );
 
@@ -98,6 +111,8 @@ abstract class LBFactory {
         * 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 array $params
         */
        abstract function forEachLB( $callback, $params = array() );
 
@@ -109,6 +124,8 @@ abstract class LBFactory {
 
        /**
         * Call a method of each tracked load balancer
+        * @param $methodName
+        * @param $args array
         */
        function forEachLBCallMethod( $methodName, $args = array() ) {
                $this->forEachLB( array( $this, 'callMethod' ), array( $methodName, $args ) );
@@ -116,6 +133,9 @@ abstract class LBFactory {
 
        /**
         * Private helper for forEachLBCallMethod
+        * @param $loadBalancer
+        * @param $methodName
+        * @param $args
         */
        function callMethod( $loadBalancer, $methodName, $args ) {
                call_user_func_array( array( $loadBalancer, $methodName ), $args );
@@ -133,6 +153,10 @@ abstract class LBFactory {
  * A simple single-master LBFactory that gets its configuration from the b/c globals
  */
 class LBFactory_Simple extends LBFactory {
+
+       /**
+        * @var LoadBalancer
+        */
        var $mainLB;
        var $extLBs = array();
 
@@ -143,6 +167,10 @@ class LBFactory_Simple extends LBFactory {
                $this->chronProt = new ChronologyProtector;
        }
 
+       /**
+        * @param $wiki
+        * @return LoadBalancer
+        */
        function newMainLB( $wiki = false ) {
                global $wgDBservers, $wgMasterWaitTimeout;
                if ( $wgDBservers ) {
@@ -166,6 +194,10 @@ class LBFactory_Simple extends LBFactory {
                ));
        }
 
+       /**
+        * @param $wiki
+        * @return LoadBalancer
+        */
        function getMainLB( $wiki = false ) {
                if ( !isset( $this->mainLB ) ) {
                        $this->mainLB = $this->newMainLB( $wiki );
@@ -175,6 +207,12 @@ class LBFactory_Simple extends LBFactory {
                return $this->mainLB;
        }
 
+       /**
+        * @throws MWException
+        * @param $cluster
+        * @param $wiki
+        * @return LoadBalancer
+        */
        function newExternalLB( $cluster, $wiki = false ) {
                global $wgExternalServers;
                if ( !isset( $wgExternalServers[$cluster] ) ) {
@@ -185,6 +223,11 @@ class LBFactory_Simple extends LBFactory {
                ));
        }
 
+       /**
+        * @param $cluster
+        * @param $wiki
+        * @return array
+        */
        function &getExternalLB( $cluster, $wiki = false ) {
                if ( !isset( $this->extLBs[$cluster] ) ) {
                        $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
@@ -197,6 +240,8 @@ class LBFactory_Simple extends LBFactory {
         * 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
         */
        function forEachLB( $callback, $params = array() ) {
                if ( isset( $this->mainLB ) ) {