MediaWiki REL1_33
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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)
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)
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:37
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.
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))
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26