MediaWiki  1.34.0
LBFactorySingle.php
Go to the documentation of this file.
1 <?php
24 namespace Wikimedia\Rdbms;
25 
26 use InvalidArgumentException;
27 use BadMethodCallException;
28 
32 class LBFactorySingle extends LBFactory {
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(
48  $this->baseLoadBalancerParams( $this->getOwnershipId() ),
49  $conf
50  ) );
51  $this->initLoadBalancer( $lb );
52 
53  $this->lb = $lb;
54  }
55 
62  public static function newFromConnection( IDatabase $db, array $params = [] ) {
63  return new static( array_merge(
64  [ 'localDomain' => $db->getDomainID() ],
65  $params,
66  [ 'connection' => $db ]
67  ) );
68  }
69 
70  public function newMainLB( $domain = false, $owner = null ) {
71  throw new BadMethodCallException( "Method is not supported." );
72  }
73 
74  public function getMainLB( $domain = false ) {
75  return $this->lb;
76  }
77 
78  public function newExternalLB( $cluster, $owner = null ) {
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 
86  public function getAllMainLBs() {
87  return [ 'DEFAULT' => $this->lb ];
88  }
89 
90  public function getAllExternalLBs() {
91  return [];
92  }
93 
94  public function forEachLB( $callback, array $params = [] ) {
95  if ( isset( $this->lb ) ) { // may not be set during _destruct()
96  $callback( $this->lb, ...$params );
97  }
98  }
99 }
Wikimedia\Rdbms\LBFactorySingle\getMainLB
getMainLB( $domain=false)
Get a cached (tracked) load balancer object.
Definition: LBFactorySingle.php:74
Wikimedia\Rdbms\LBFactorySingle\getAllExternalLBs
getAllExternalLBs()
Get cached (tracked) load balancers for all external database clusters.
Definition: LBFactorySingle.php:90
Wikimedia\Rdbms\LoadBalancerSingle
Trivial LoadBalancer that always returns an injected connection handle.
Definition: LoadBalancerSingle.php:31
Wikimedia\Rdbms\LBFactory\initLoadBalancer
initLoadBalancer(ILoadBalancer $lb)
Definition: LBFactory.php:624
Wikimedia\Rdbms\LBFactory\getOwnershipId
getOwnershipId()
Definition: LBFactory.php:739
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\LBFactorySingle\newFromConnection
static newFromConnection(IDatabase $db, array $params=[])
Definition: LBFactorySingle.php:62
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Wikimedia\Rdbms\LBFactorySingle
An LBFactory class that always returns a single database object.
Definition: LBFactorySingle.php:32
Wikimedia\Rdbms\LBFactorySingle\getExternalLB
getExternalLB( $cluster)
Get a cached (tracked) load balancer for external storage.
Definition: LBFactorySingle.php:82
Wikimedia\Rdbms\LBFactory\baseLoadBalancerParams
baseLoadBalancerParams( $owner)
Get parameters to ILoadBalancer::__construct()
Definition: LBFactory.php:585
Wikimedia\Rdbms\LBFactorySingle\$lb
LoadBalancerSingle $lb
Definition: LBFactorySingle.php:34
Wikimedia\Rdbms\LBFactorySingle\getAllMainLBs
getAllMainLBs()
Get cached (tracked) load balancers for all main database clusters.
Definition: LBFactorySingle.php:86
Wikimedia\Rdbms\IDatabase\getDomainID
getDomainID()
Return the currently selected domain ID.
Wikimedia\Rdbms\LBFactorySingle\forEachLB
forEachLB( $callback, array $params=[])
Execute a function for each currently tracked (instantiated) load balancer.
Definition: LBFactorySingle.php:94
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:40
Wikimedia\Rdbms\LBFactorySingle\__construct
__construct(array $conf)
Definition: LBFactorySingle.php:40
Wikimedia\Rdbms\LBFactorySingle\newMainLB
newMainLB( $domain=false, $owner=null)
Create a new load balancer object.
Definition: LBFactorySingle.php:70
Wikimedia\Rdbms\LBFactorySingle\newExternalLB
newExternalLB( $cluster, $owner=null)
Create a new load balancer for external storage.
Definition: LBFactorySingle.php:78