MediaWiki REL1_31
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' => isset( $params['trxProfiler'] ) ? $params['trxProfiler'] : null,
56 'srvCache' => isset( $params['srvCache'] ) ? $params['srvCache'] : null,
57 'wanCache' => isset( $params['wanCache'] ) ? $params['wanCache'] : null
58 ] );
59
60 if ( isset( $params['readOnlyReason'] ) ) {
61 $this->db->setLBInfo( 'readOnlyReason', $params['readOnlyReason'] );
62 }
63 }
64
71 public static function newFromConnection( IDatabase $db, array $params = [] ) {
72 return new static( [ 'connection' => $db ] + $params );
73 }
74
75 protected function reallyOpenConnection( array $server, DatabaseDomain $domainOverride ) {
76 return $this->db;
77 }
78}
79
80class_alias( LoadBalancerSingle::class, 'LoadBalancerSingle' );
Class to handle database/prefix specification for IDatabase domains.
Trivial LoadBalancer that always returns an injected connection handle.
static newFromConnection(IDatabase $db, array $params=[])
reallyOpenConnection(array $server, DatabaseDomain $domainOverride)
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
$params