MediaWiki  1.32.5
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( array_merge(
60  [ 'localDomain' => $db->getDomainID() ],
61  $params,
62  [ 'connection' => $db ]
63  ) );
64  }
65 
70  public function newMainLB( $domain = false ) {
71  return $this->lb;
72  }
73 
78  public function getMainLB( $domain = false ) {
79  return $this->lb;
80  }
81 
82  public function newExternalLB( $cluster ) {
83  throw new BadMethodCallException( "Method is not supported." );
84  }
85 
86  public function getExternalLB( $cluster ) {
87  throw new BadMethodCallException( "Method is not supported." );
88  }
89 
93  public function getAllMainLBs() {
94  return [ 'DEFAULT' => $this->lb ];
95  }
96 
100  public function getAllExternalLBs() {
101  return [];
102  }
103 
108  public function forEachLB( $callback, array $params = [] ) {
109  if ( isset( $this->lb ) ) { // may not be set during _destruct()
110  $callback( $this->lb, ...$params );
111  }
112  }
113 }
Wikimedia\Rdbms\LBFactorySingle\getMainLB
getMainLB( $domain=false)
Definition: LBFactorySingle.php:78
Wikimedia\Rdbms\LBFactorySingle\newMainLB
newMainLB( $domain=false)
Definition: LBFactorySingle.php:70
Wikimedia\Rdbms\LBFactorySingle\getAllExternalLBs
getAllExternalLBs()
Definition: LBFactorySingle.php:100
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:604
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
$params
$params
Definition: styleTest.css.php:44
Wikimedia\Rdbms\LBFactorySingle\newFromConnection
static newFromConnection(IDatabase $db, array $params=[])
Definition: LBFactorySingle.php:58
Wikimedia\Rdbms\LBFactory\baseLoadBalancerParams
baseLoadBalancerParams()
Base parameters to ILoadBalancer::__construct()
Definition: LBFactory.php:567
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:38
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:86
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\LBFactorySingle\$lb
LoadBalancerSingle $lb
Definition: LBFactorySingle.php:34
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Wikimedia\Rdbms\LBFactorySingle\getAllMainLBs
getAllMainLBs()
Definition: LBFactorySingle.php:93
Wikimedia\Rdbms\IDatabase\getDomainID
getDomainID()
Return the currently selected domain ID.
Wikimedia\Rdbms\LBFactorySingle\forEachLB
forEachLB( $callback, array $params=[])
Definition: LBFactorySingle.php:108
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:39
Wikimedia\Rdbms\LBFactorySingle\__construct
__construct(array $conf)
Definition: LBFactorySingle.php:40
Wikimedia\Rdbms\LBFactorySingle\newExternalLB
newExternalLB( $cluster)
Definition: LBFactorySingle.php:82