MediaWiki  1.30.2
ConnectionManager.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Rdbms;
4 
5 use InvalidArgumentException;
6 
18 
22  private $loadBalancer;
23 
29  private $domain;
30 
34  private $groups = [];
35 
44  public function __construct( LoadBalancer $loadBalancer, $domain = false, array $groups = [] ) {
45  if ( !is_string( $domain ) && $domain !== false ) {
46  throw new InvalidArgumentException( '$dbName must be a string, or false.' );
47  }
48 
49  $this->loadBalancer = $loadBalancer;
50  $this->domain = $domain;
51  $this->groups = $groups;
52  }
53 
60  private function getConnection( $i, array $groups = null ) {
61  $groups = $groups === null ? $this->groups : $groups;
62  return $this->loadBalancer->getConnection( $i, $groups, $this->domain );
63  }
64 
71  private function getConnectionRef( $i, array $groups = null ) {
72  $groups = $groups === null ? $this->groups : $groups;
73  return $this->loadBalancer->getConnectionRef( $i, $groups, $this->domain );
74  }
75 
84  public function getWriteConnection() {
85  return $this->getConnection( DB_MASTER );
86  }
87 
98  public function getReadConnection( array $groups = null ) {
99  $groups = $groups === null ? $this->groups : $groups;
100  return $this->getConnection( DB_REPLICA, $groups );
101  }
102 
108  public function releaseConnection( IDatabase $db ) {
109  $this->loadBalancer->reuseConnection( $db );
110  }
111 
119  public function getWriteConnectionRef() {
120  return $this->getConnectionRef( DB_MASTER );
121  }
122 
132  public function getReadConnectionRef( array $groups = null ) {
133  $groups = $groups === null ? $this->groups : $groups;
134  return $this->getConnectionRef( DB_REPLICA, $groups );
135  }
136 
137 }
Wikimedia\Rdbms\ConnectionManager\__construct
__construct(LoadBalancer $loadBalancer, $domain=false, array $groups=[])
Definition: ConnectionManager.php:44
Wikimedia\Rdbms\ConnectionManager\getWriteConnectionRef
getWriteConnectionRef()
Returns a connection ref to the master DB, for updating.
Definition: ConnectionManager.php:119
Wikimedia\Rdbms\ConnectionManager\getReadConnection
getReadConnection(array $groups=null)
Returns a database connection for reading.
Definition: ConnectionManager.php:98
Wikimedia\Rdbms\ConnectionManager\getWriteConnection
getWriteConnection()
Returns a connection to the master DB, for updating.
Definition: ConnectionManager.php:84
Wikimedia\Rdbms\ConnectionManager\releaseConnection
releaseConnection(IDatabase $db)
Definition: ConnectionManager.php:108
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\ConnectionManager\$loadBalancer
LoadBalancer $loadBalancer
Definition: ConnectionManager.php:22
Wikimedia\Rdbms\ConnectionManager\$groups
string[] $groups
Definition: ConnectionManager.php:34
Wikimedia\Rdbms\ConnectionManager\$domain
string false $domain
The symbolic name of the target database, or false for the local wiki's database.
Definition: ConnectionManager.php:29
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Wikimedia\Rdbms\LoadBalancer
Database connection, tracking, load balancing, and transaction manager for a cluster.
Definition: LoadBalancer.php:41
Wikimedia\Rdbms\ConnectionManager\getConnectionRef
getConnectionRef( $i, array $groups=null)
Definition: ConnectionManager.php:71
groups
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)
Wikimedia\Rdbms\ConnectionManager
Database connection manager.
Definition: ConnectionManager.php:17
Wikimedia\Rdbms\ConnectionManager\getConnection
getConnection( $i, array $groups=null)
Definition: ConnectionManager.php:60
Wikimedia\Rdbms\ConnectionManager\getReadConnectionRef
getReadConnectionRef(array $groups=null)
Returns a database connection ref for reading.
Definition: ConnectionManager.php:132
array
the array() calling protocol came about after MediaWiki 1.4rc1.