MediaWiki REL1_34
ConnectionManager.php
Go to the documentation of this file.
1<?php
22namespace Wikimedia\Rdbms;
23
24use InvalidArgumentException;
25
36
41
47 private $domain;
48
52 private $groups = [];
53
62 public function __construct( ILoadBalancer $loadBalancer, $domain = false, array $groups = [] ) {
63 if ( !is_string( $domain ) && $domain !== false ) {
64 throw new InvalidArgumentException( '$dbName must be a string, or false.' );
65 }
66
67 $this->loadBalancer = $loadBalancer;
68 $this->domain = $domain;
69 $this->groups = $groups;
70 }
71
78 private function getConnection( $i, array $groups = null ) {
79 $groups = $groups === null ? $this->groups : $groups;
80 return $this->loadBalancer->getConnection( $i, $groups, $this->domain );
81 }
82
89 private function getConnectionRef( $i, array $groups = null ) {
90 $groups = $groups === null ? $this->groups : $groups;
91 return $this->loadBalancer->getConnectionRef( $i, $groups, $this->domain );
92 }
93
102 public function getWriteConnection() {
103 return $this->getConnection( DB_MASTER );
104 }
105
116 public function getReadConnection( array $groups = null ) {
117 $groups = $groups === null ? $this->groups : $groups;
118 return $this->getConnection( DB_REPLICA, $groups );
119 }
120
126 public function releaseConnection( IDatabase $db ) {
127 $this->loadBalancer->reuseConnection( $db );
128 }
129
137 public function getWriteConnectionRef() {
138 return $this->getConnectionRef( DB_MASTER );
139 }
140
150 public function getReadConnectionRef( array $groups = null ) {
151 $groups = $groups === null ? $this->groups : $groups;
152 return $this->getConnectionRef( DB_REPLICA, $groups );
153 }
154
155}
Database connection manager.
getWriteConnectionRef()
Returns a connection ref to the master DB, for updating.
__construct(ILoadBalancer $loadBalancer, $domain=false, array $groups=[])
getWriteConnection()
Returns a connection to the master DB, for updating.
string false $domain
The symbolic name of the target database, or false for the local wiki's database.
getConnection( $i, array $groups=null)
getReadConnectionRef(array $groups=null)
Returns a database connection ref for reading.
getReadConnection(array $groups=null)
Returns a database connection for reading.
getConnectionRef( $i, array $groups=null)
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Database cluster connection, tracking, load balancing, and transaction manager interface.
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26