MediaWiki REL1_37
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
79 private function getConnection( $i, ?array $groups = null, int $flags = 0 ) {
81 return $this->loadBalancer->getConnection( $i, $groups, $this->domain, $flags );
82 }
83
90 private function getConnectionRef( $i, array $groups = null ) {
92 return $this->loadBalancer->getConnectionRef( $i, $groups, $this->domain );
93 }
94
101 private function getLazyConnectionRef( $i, array $groups = null ) {
103 return $this->loadBalancer->getLazyConnectionRef( $i, $groups, $this->domain );
104 }
105
117 public function getWriteConnection( int $flags = 0 ) {
118 return $this->getConnection( DB_PRIMARY, null, $flags );
119 }
120
133 public function getReadConnection( ?array $groups = null, int $flags = 0 ) {
135 return $this->getConnection( DB_REPLICA, $groups, $flags );
136 }
137
143 public function releaseConnection( IDatabase $db ) {
144 $this->loadBalancer->reuseConnection( $db );
145 }
146
154 public function getWriteConnectionRef() {
155 return $this->getConnectionRef( DB_PRIMARY );
156 }
157
167 public function getReadConnectionRef( array $groups = null ) {
169 return $this->getConnectionRef( DB_REPLICA, $groups );
170 }
171
181 public function getLazyReadConnectionRef( array $groups = null ) {
183 return $this->getLazyConnectionRef( DB_REPLICA, $groups );
184 }
185
186}
Database connection manager.
getWriteConnectionRef()
Returns a connection ref to the primary DB, for updating.
__construct(ILoadBalancer $loadBalancer, $domain=false, array $groups=[])
getLazyReadConnectionRef(array $groups=null)
Returns a lazy-connecting database connection ref for reading.
getWriteConnection(int $flags=0)
Returns a connection to the primary 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, int $flags=0)
getReadConnectionRef(array $groups=null)
Returns a database connection ref for reading.
getLazyConnectionRef( $i, array $groups=null)
getConnectionRef( $i, array $groups=null)
getReadConnection(?array $groups=null, int $flags=0)
Returns a database connection for reading.
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_PRIMARY
Definition defines.php:27