3 * Simple generator of database connections that always returns the same object.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * An LBFactory class that always returns a single database object.
27 class LBFactorySingle
extends LBFactory
{
28 /** @var LoadBalancerSingle */
32 * @param array $conf An associative array with one member:
33 * - connection: The IDatabase connection object
35 public function __construct( array $conf ) {
36 parent
::__construct( $conf );
38 if ( !isset( $conf['connection'] ) ) {
39 throw new InvalidArgumentException( "Missing 'connection' argument." );
42 $this->lb
= new LoadBalancerSingle( array_merge( $this->baseLoadBalancerParams(), $conf ) );
46 * @param IDatabase $db Live connection handle
47 * @param array $params Parameter map to LBFactorySingle::__constructs()
48 * @return LBFactorySingle
51 public static function newFromConnection( IDatabase
$db, array $params = [] ) {
52 return new static( [ 'connection' => $db ] +
$params );
56 * @param bool|string $wiki
57 * @return LoadBalancerSingle
59 public function newMainLB( $wiki = false ) {
64 * @param bool|string $wiki
65 * @return LoadBalancerSingle
67 public function getMainLB( $wiki = false ) {
72 * @param string $cluster External storage cluster, or false for core
73 * @param bool|string $wiki Wiki ID, or false for the current wiki
74 * @return LoadBalancerSingle
76 protected function newExternalLB( $cluster, $wiki = false ) {
81 * @param string $cluster External storage cluster, or false for core
82 * @param bool|string $wiki Wiki ID, or false for the current wiki
83 * @return LoadBalancerSingle
85 public function getExternalLB( $cluster, $wiki = false ) {
90 * @param string|callable $callback
91 * @param array $params
93 public function forEachLB( $callback, array $params = [] ) {
94 call_user_func_array( $callback, array_merge( [ $this->lb
], $params ) );