d29258f4bb800495cf77358a7d787872e5ddee3f
3 * Simple generator of database connections that always returns the same object.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 namespace Wikimedia\Rdbms
;
26 use InvalidArgumentException
;
29 * Trivial LoadBalancer that always returns an injected connection handle
31 class LoadBalancerSingle
extends LoadBalancer
{
36 * @param array $params An associative array with one member:
37 * - connection: An IDatabase connection object
39 public function __construct( array $params ) {
40 if ( !isset( $params['connection'] ) ) {
41 throw new InvalidArgumentException( "Missing 'connection' argument." );
44 $this->db
= $params['connection'];
46 parent
::__construct( [
49 'type' => $this->db
->getType(),
50 'host' => $this->db
->getServer(),
51 'dbname' => $this->db
->getDBname(),
55 'trxProfiler' => isset( $params['trxProfiler'] ) ?
$params['trxProfiler'] : null,
56 'srvCache' => isset( $params['srvCache'] ) ?
$params['srvCache'] : null,
57 'wanCache' => isset( $params['wanCache'] ) ?
$params['wanCache'] : null
60 if ( isset( $params['readOnlyReason'] ) ) {
61 $this->db
->setLBInfo( 'readOnlyReason', $params['readOnlyReason'] );
66 * @param IDatabase $db Live connection handle
67 * @param array $params Parameter map to LoadBalancerSingle::__constructs()
68 * @return LoadBalancerSingle
71 public static function newFromConnection( IDatabase
$db, array $params = [] ) {
72 return new static( [ 'connection' => $db ] +
$params );
75 protected function reallyOpenConnection( array $server, DatabaseDomain
$domainOverride ) {
81 * @deprecated since 1.29
83 class_alias( LoadBalancerSingle
::class, 'LoadBalancerSingle' );