MediaWiki REL1_31
LBFactorySingle.php
Go to the documentation of this file.
1<?php
24namespace Wikimedia\Rdbms;
25
26use InvalidArgumentException;
27use BadMethodCallException;
28
34 private $lb;
35
40 public function __construct( array $conf ) {
41 parent::__construct( $conf );
42
43 if ( !isset( $conf['connection'] ) ) {
44 throw new InvalidArgumentException( "Missing 'connection' argument." );
45 }
46
47 $lb = new LoadBalancerSingle( array_merge( $this->baseLoadBalancerParams(), $conf ) );
48 $this->initLoadBalancer( $lb );
49 $this->lb = $lb;
50 }
51
58 public static function newFromConnection( IDatabase $db, array $params = [] ) {
59 return new static( [ 'connection' => $db ] + $params );
60 }
61
66 public function newMainLB( $domain = false ) {
67 return $this->lb;
68 }
69
74 public function getMainLB( $domain = false ) {
75 return $this->lb;
76 }
77
78 public function newExternalLB( $cluster ) {
79 throw new BadMethodCallException( "Method is not supported." );
80 }
81
82 public function getExternalLB( $cluster ) {
83 throw new BadMethodCallException( "Method is not supported." );
84 }
85
89 public function getAllMainLBs() {
90 return [ 'DEFAULT' => $this->lb ];
91 }
92
96 public function getAllExternalLBs() {
97 return [];
98 }
99
104 public function forEachLB( $callback, array $params = [] ) {
105 if ( isset( $this->lb ) ) { // may not be set during _destruct()
106 call_user_func_array( $callback, array_merge( [ $this->lb ], $params ) );
107 }
108 }
109}
An LBFactory class that always returns a single database object.
forEachLB( $callback, array $params=[])
static newFromConnection(IDatabase $db, array $params=[])
An interface for generating database load balancers.
Definition LBFactory.php:39
initLoadBalancer(ILoadBalancer $lb)
baseLoadBalancerParams()
Base parameters to LoadBalancer::__construct()
Trivial LoadBalancer that always returns an injected connection handle.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
$params