MediaWiki  1.33.0
ConnectionManager.php
Go to the documentation of this file.
1 <?php
22 namespace Wikimedia\Rdbms;
23 
24 use InvalidArgumentException;
25 
36 
40  private $loadBalancer;
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 }
Wikimedia\Rdbms\ConnectionManager\getWriteConnectionRef
getWriteConnectionRef()
Returns a connection ref to the master DB, for updating.
Definition: ConnectionManager.php:137
Wikimedia\Rdbms\ConnectionManager\getReadConnection
getReadConnection(array $groups=null)
Returns a database connection for reading.
Definition: ConnectionManager.php:116
Wikimedia\Rdbms\ConnectionManager\getWriteConnection
getWriteConnection()
Returns a connection to the master DB, for updating.
Definition: ConnectionManager.php:102
Wikimedia\Rdbms\ConnectionManager\releaseConnection
releaseConnection(IDatabase $db)
Definition: ConnectionManager.php:126
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\ConnectionManager\$groups
string[] $groups
Definition: ConnectionManager.php:52
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:47
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:38
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
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Wikimedia\Rdbms\ConnectionManager\__construct
__construct(ILoadBalancer $loadBalancer, $domain=false, array $groups=[])
Definition: ConnectionManager.php:62
groups
this hook is for auditing only 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\getConnectionRef
getConnectionRef( $i, array $groups=null)
Definition: ConnectionManager.php:89
Wikimedia\Rdbms\ConnectionManager
Database connection manager.
Definition: ConnectionManager.php:35
Wikimedia\Rdbms\ConnectionManager\getConnection
getConnection( $i, array $groups=null)
Definition: ConnectionManager.php:78
Wikimedia\Rdbms\ConnectionManager\getReadConnectionRef
getReadConnectionRef(array $groups=null)
Returns a database connection ref for reading.
Definition: ConnectionManager.php:150
Wikimedia\Rdbms\ConnectionManager\$loadBalancer
ILoadBalancer $loadBalancer
Definition: ConnectionManager.php:40
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:78