MediaWiki REL1_32
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( 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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 ILoadBalancer::__construct()
Trivial LoadBalancer that always returns an injected connection handle.
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:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
getDomainID()
Return the currently selected domain ID.
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))
$params