MediaWiki REL1_35
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 ) {
41 $conn = $params['connection'] ?? null;
42 if ( !$conn ) {
43 throw new InvalidArgumentException( "Missing 'connection' argument." );
44 }
45
46 $this->db = $conn;
47
48 parent::__construct( [
49 'servers' => [ [
50 'type' => $conn->getType(),
51 'host' => $conn->getServer(),
52 'dbname' => $conn->getDBname(),
53 'load' => 1,
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 $conn->setLBInfo( $conn::LB_READ_ONLY_REASON, $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( $i, DatabaseDomain $domain, array $lbInfo = [] ) {
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( $i, DatabaseDomain $domain, array $lbInfo=[])
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.