MediaWiki REL1_39
LoadBalancerSingle.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
22use InvalidArgumentException;
23
31 private $db;
32
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 'clusterName' => $params['clusterName'] ?? null,
61 ] );
62
63 if ( isset( $params['readOnlyReason'] ) ) {
64 $conn->setLBInfo( $conn::LB_READ_ONLY_REASON, $params['readOnlyReason'] );
65 }
66 }
67
74 public static function newFromConnection( IDatabase $db, array $params = [] ) {
75 return new static( array_merge(
76 [ 'localDomain' => $db->getDomainID() ],
77 $params,
78 [ 'connection' => $db ]
79 ) );
80 }
81
82 protected function reallyOpenConnection( $i, DatabaseDomain $domain, array $lbInfo = [] ) {
83 return $this->db;
84 }
85
86 public function __destruct() {
87 // do nothing since the connection was injected
88 }
89}
90
94class_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=[])
__construct(array $params)
You probably want to use newFromConnection instead.
reallyOpenConnection( $i, DatabaseDomain $domain, array $lbInfo=[])
Open a new network connection to a server (uncached)
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
getDomainID()
Return the currently selected domain ID.