MediaWiki REL1_31
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( LoadBalancer $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.
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)
__construct(LoadBalancer $loadBalancer, $domain=false, array $groups=[])
Database connection, tracking, load balancing, and transaction manager for a cluster.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing groups(accessed through $special->getFilterGroup)
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:29