Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
LoadBalancerDisabled
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 7
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 reallyOpenConnection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConnection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConnectionInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConnectionRef
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMaintenanceConnectionRef
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 reuseConnection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20namespace Wikimedia\Rdbms;
21
22use RuntimeException;
23
24/**
25 * Trivial LoadBalancer that always fails.
26 * Useful when running code with no config file present,
27 * e.g. during the installation process.
28 *
29 * @since 1.40
30 *
31 * @ingroup Database
32 */
33class LoadBalancerDisabled extends LoadBalancer {
34
35    public function __construct( $params = [] ) {
36        parent::__construct( [
37            'servers' => [ [
38                'type' => 'disabled',
39                'host' => '(disabled)',
40                'dbname' => null,
41                'load' => 1,
42            ] ],
43            'trxProfiler' => $params['trxProfiler'] ?? null,
44            'srvCache' => $params['srvCache'] ?? null,
45            'wanCache' => $params['wanCache'] ?? null,
46            'localDomain' => $params['localDomain'] ?? '(disabled)',
47            'readOnlyReason' => $params['readOnlyReason'] ?? false,
48            'clusterName' => $params['clusterName'] ?? null,
49        ] );
50    }
51
52    /**
53     * @param int $i
54     * @param DatabaseDomain $domain
55     * @param array $lbInfo
56     *
57     * @return never
58     */
59    protected function reallyOpenConnection( $i, DatabaseDomain $domain, array $lbInfo ) {
60        throw new RuntimeException( 'Database backend disabled' );
61    }
62
63    /**
64     * @param int $i Specific (overrides $groups) or virtual (DB_PRIMARY/DB_REPLICA) server index
65     * @param string[]|string $groups Query group(s) in preference order; [] for the default group
66     * @param string|false $domain DB domain ID or false for the local domain
67     * @param int $flags Bitfield of CONN_* class constants
68     *
69     * @return never
70     */
71    public function getConnection( $i, $groups = [], $domain = false, $flags = 0 ) {
72        throw new RuntimeException( 'Database backend disabled' );
73    }
74
75    /**
76     * @internal Only to be used by DBConnRef
77     * @param int $i Specific (overrides $groups) or virtual (DB_PRIMARY/DB_REPLICA) server index
78     * @param string[]|string $groups Query group(s) in preference order; [] for the default group
79     * @param string|false $domain DB domain ID or false for the local domain
80     * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
81     * @return never
82     */
83    public function getConnectionInternal( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase {
84        throw new RuntimeException( 'Database backend disabled' );
85    }
86
87    /**
88     * @param int $i Specific (overrides $groups) or virtual (DB_PRIMARY/DB_REPLICA) server index
89     * @param string[]|string $groups Query group(s) in preference order; [] for the default group
90     * @param string|false $domain DB domain ID or false for the local domain
91     * @param int $flags Bitfield of CONN_* class constants
92     *
93     * @return never
94     */
95    public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): DBConnRef {
96        throw new RuntimeException( 'Database backend disabled' );
97    }
98
99    /**
100     * @param int $i Specific (overrides $groups) or virtual (DB_PRIMARY/DB_REPLICA) server index
101     * @param string[]|string $groups Query group(s) in preference order; [] for the default group
102     * @param string|false $domain DB domain ID or false for the local domain
103     * @param int $flags Bitfield of CONN_* class constants
104     *
105     * @return never
106     */
107    public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): DBConnRef {
108        throw new RuntimeException( 'Database backend disabled' );
109    }
110
111    public function reuseConnection( IDatabase $conn ) {
112        // noop
113    }
114
115}