MediaWiki  1.30.2
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( $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  call_user_func_array( $callback, array_merge( [ $this->lb ], $params ) );
106  }
107 }
Wikimedia\Rdbms\LBFactorySingle\getMainLB
getMainLB( $domain=false)
Definition: LBFactorySingle.php:74
Wikimedia\Rdbms\LBFactorySingle\newMainLB
newMainLB( $domain=false)
Definition: LBFactorySingle.php:66
Wikimedia\Rdbms\LBFactorySingle\getAllExternalLBs
getAllExternalLBs()
Definition: LBFactorySingle.php:96
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:520
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
$params
$params
Definition: styleTest.css.php:40
Wikimedia\Rdbms\LBFactorySingle\newFromConnection
static newFromConnection(IDatabase $db, array $params=[])
Definition: LBFactorySingle.php:58
Wikimedia\Rdbms\LBFactory\baseLoadBalancerParams
baseLoadBalancerParams()
Base parameters to LoadBalancer::__construct()
Definition: LBFactory.php:498
php
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
Wikimedia\Rdbms\LBFactorySingle
An LBFactory class that always returns a single database object.
Definition: LBFactorySingle.php:32
Wikimedia\Rdbms\LBFactorySingle\getExternalLB
getExternalLB( $cluster)
Definition: LBFactorySingle.php:82
Wikimedia\Rdbms\LBFactorySingle\$lb
LoadBalancerSingle $lb
Definition: LBFactorySingle.php:34
Wikimedia\Rdbms\LBFactorySingle\getAllMainLBs
getAllMainLBs()
Definition: LBFactorySingle.php:89
Wikimedia\Rdbms\LBFactorySingle\forEachLB
forEachLB( $callback, array $params=[])
Definition: LBFactorySingle.php:104
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:38
Wikimedia\Rdbms\LBFactorySingle\__construct
__construct(array $conf)
Definition: LBFactorySingle.php:40
Wikimedia\Rdbms\LBFactorySingle\newExternalLB
newExternalLB( $cluster)
Definition: LBFactorySingle.php:78
array
the array() calling protocol came about after MediaWiki 1.4rc1.