MediaWiki REL1_34
LoadBalancerSingle.php
Go to the documentation of this file.
1<?php
24namespace Wikimedia\Rdbms;
25
26use 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 'readOnlyReason' => $params['readOnlyReason'] ?? false,
60 ] );
61
62 if ( isset( $params['readOnlyReason'] ) ) {
63 $this->db->setLBInfo( 'readOnlyReason', $params['readOnlyReason'] );
64 }
65 }
66
73 public static function newFromConnection( IDatabase $db, array $params = [] ) {
74 return new static( array_merge(
75 [ 'localDomain' => $db->getDomainID() ],
76 $params,
77 [ 'connection' => $db ]
78 ) );
79 }
80
81 protected function reallyOpenConnection( array $server, DatabaseDomain $domain ) {
82 return $this->db;
83 }
84
85 public function __destruct() {
86 // do nothing since the connection was injected
87 }
88}
89
93class_alias( LoadBalancerSingle::class, 'LoadBalancerSingle' );
Class to handle database/schema/prefix specifications for IDatabase.
Trivial LoadBalancer that always returns an injected connection handle.
static newFromConnection(IDatabase $db, array $params=[])
reallyOpenConnection(array $server, DatabaseDomain $domain)
Open a new network connection to a server (uncached)
Database connection, tracking, load balancing, and transaction manager for a cluster.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
getDomainID()
Return the currently selected domain ID.