MediaWiki  1.28.1
Go to the documentation of this file.
1 <?php
27 class LBFactorySingle extends LBFactory {
29  private $lb;
35  public function __construct( array $conf ) {
36  parent::__construct( $conf );
38  if ( !isset( $conf['connection'] ) ) {
39  throw new InvalidArgumentException( "Missing 'connection' argument." );
40  }
42  $lb = new LoadBalancerSingle( array_merge( $this->baseLoadBalancerParams(), $conf ) );
43  $this->initLoadBalancer( $lb );
44  $this->lb = $lb;
45  }
53  public static function newFromConnection( IDatabase $db, array $params = [] ) {
54  return new static( [ 'connection' => $db ] + $params );
55  }
61  public function newMainLB( $domain = false ) {
62  return $this->lb;
63  }
69  public function getMainLB( $domain = false ) {
70  return $this->lb;
71  }
77  public function newExternalLB( $cluster ) {
78  return $this->lb;
79  }
85  public function getExternalLB( $cluster ) {
86  return $this->lb;
87  }
93  public function forEachLB( $callback, array $params = [] ) {
94  call_user_func_array( $callback, array_merge( [ $this->lb ], $params ) );
95  }
96 }
the array() calling protocol came about after MediaWiki 1.4rc1.
An LBFactory class that always returns a single database object.
Base parameters to LoadBalancer::__construct()
Definition: LBFactory.php:486
static newFromConnection(IDatabase $db, array $params=[])
__construct(array $conf)
initLoadBalancer(ILoadBalancer $lb)
Definition: LBFactory.php:507
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
forEachLB($callback, array $params=[])
Trivial LoadBalancer that always returns an injected connection handle.
LoadBalancerSingle $lb
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:34