Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / db / LBFactory_Single.php
blob7dca06d7d76617acfca6797b4df66f936370f6b0
1 <?php
2 /**
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
20 * @file
21 * @ingroup Database
24 /**
25 * An LBFactory class that always returns a single database object.
27 class LBFactory_Single extends LBFactory {
28 protected $lb;
30 /**
31 * @param array $conf An associative array with one member:
32 * - connection: The DatabaseBase connection object
34 function __construct( $conf ) {
35 $this->lb = new LoadBalancer_Single( $conf );
38 /**
39 * @param $wiki bool|string
41 * @return LoadBalancer_Single
43 function newMainLB( $wiki = false ) {
44 return $this->lb;
47 /**
48 * @param $wiki bool|string
50 * @return LoadBalancer_Single
52 function getMainLB( $wiki = false ) {
53 return $this->lb;
56 /**
57 * @param $cluster
58 * @param $wiki bool|string
60 * @return LoadBalancer_Single
62 function newExternalLB( $cluster, $wiki = false ) {
63 return $this->lb;
66 /**
67 * @param $cluster
68 * @param $wiki bool|string
70 * @return LoadBalancer_Single
72 function &getExternalLB( $cluster, $wiki = false ) {
73 return $this->lb;
76 /**
77 * @param $callback string|array
78 * @param $params array
80 function forEachLB( $callback, $params = array() ) {
81 call_user_func_array( $callback, array_merge( array( $this->lb ), $params ) );
85 /**
86 * Helper class for LBFactory_Single.
88 class LoadBalancer_Single extends LoadBalancer {
90 /**
91 * @var DatabaseBase
93 var $db;
95 /**
96 * @param $params array
98 function __construct( $params ) {
99 $this->db = $params['connection'];
100 parent::__construct( array( 'servers' => array( array(
101 'type' => $this->db->getType(),
102 'host' => $this->db->getServer(),
103 'dbname' => $this->db->getDBname(),
104 'load' => 1,
105 ) ) ) );
110 * @param $server string
111 * @param $dbNameOverride bool
113 * @return DatabaseBase
115 function reallyOpenConnection( $server, $dbNameOverride = false ) {
116 return $this->db;