MediaWiki  1.32.5
LoadBalancerSingle.php
Go to the documentation of this file.
1 <?php
24 namespace Wikimedia\Rdbms;
25 
26 use InvalidArgumentException;
27 
33  private $db;
34 
39  public function __construct( array $params ) {
40  if ( !isset( $params['connection'] ) ) {
41  throw new InvalidArgumentException( "Missing 'connection' argument." );
42  }
43 
44  $this->db = $params['connection'];
45 
46  parent::__construct( [
47  'servers' => [
48  [
49  'type' => $this->db->getType(),
50  'host' => $this->db->getServer(),
51  'dbname' => $this->db->getDBname(),
52  'load' => 1,
53  ]
54  ],
55  'trxProfiler' => $params['trxProfiler'] ?? null,
56  'srvCache' => $params['srvCache'] ?? null,
57  'wanCache' => $params['wanCache'] ?? null,
58  'localDomain' => $params['localDomain'] ?? $this->db->getDomainID()
59  ] );
60 
61  if ( isset( $params['readOnlyReason'] ) ) {
62  $this->db->setLBInfo( 'readOnlyReason', $params['readOnlyReason'] );
63  }
64  }
65 
72  public static function newFromConnection( IDatabase $db, array $params = [] ) {
73  return new static( array_merge(
74  [ 'localDomain' => $db->getDomainID() ],
75  $params,
76  [ 'connection' => $db ]
77  ) );
78  }
79 
80  protected function reallyOpenConnection( array $server, DatabaseDomain $domain ) {
81  return $this->db;
82  }
83 }
84 
88 class_alias( LoadBalancerSingle::class, 'LoadBalancerSingle' );
Wikimedia\Rdbms\LoadBalancerSingle
Trivial LoadBalancer that always returns an injected connection handle.
Definition: LoadBalancerSingle.php:31
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\LoadBalancerSingle\reallyOpenConnection
reallyOpenConnection(array $server, DatabaseDomain $domain)
Open a new network connection to a server (uncached)
Definition: LoadBalancerSingle.php:80
$params
$params
Definition: styleTest.css.php:44
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
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
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\LoadBalancer
Database connection, tracking, load balancing, and transaction manager for a cluster.
Definition: LoadBalancer.php:41
Wikimedia\Rdbms\LoadBalancerSingle\newFromConnection
static newFromConnection(IDatabase $db, array $params=[])
Definition: LoadBalancerSingle.php:72
Wikimedia\Rdbms\IDatabase\getDomainID
getDomainID()
Return the currently selected domain ID.
Wikimedia\Rdbms\LoadBalancerSingle\$db
IDatabase $db
Definition: LoadBalancerSingle.php:33
Wikimedia\Rdbms\LoadBalancerSingle\__construct
__construct(array $params)
Definition: LoadBalancerSingle.php:39
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Wikimedia\Rdbms\DatabaseDomain
Class to handle database/prefix specification for IDatabase domains.
Definition: DatabaseDomain.php:28