Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ForeignDBViaLBRepo
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 7
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getPrimaryDB
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getReplicaDB
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDBFactory
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getDbProvider
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 assertWritableRepo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInfo
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 */
20
21use MediaWiki\MediaWikiServices;
22use Wikimedia\Rdbms\IConnectionProvider;
23
24/**
25 * A foreign repository with a MediaWiki database accessible via the configured LBFactory.
26 *
27 * @ingroup FileRepo
28 */
29class ForeignDBViaLBRepo extends LocalRepo implements IForeignRepoWithDB {
30    /** @var array */
31    protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
32
33    /** @var array */
34    protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
35
36    /**
37     * @param array|null $info
38     */
39    public function __construct( $info ) {
40        parent::__construct( $info );
41        '@phan-var array $info';
42        $this->dbDomain = $info['wiki'];
43        $this->hasAccessibleSharedCache = $info['hasSharedCache'];
44    }
45
46    public function getPrimaryDB() {
47        return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain );
48    }
49
50    public function getReplicaDB() {
51        return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain );
52    }
53
54    /**
55     * @return Closure
56     */
57    protected function getDBFactory() {
58        return function ( $index ) {
59            if ( $index == DB_PRIMARY ) {
60                return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain );
61            } else {
62                return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain );
63            }
64        };
65    }
66
67    /**
68     * @return IConnectionProvider
69     */
70    protected function getDbProvider(): IConnectionProvider {
71        return MediaWikiServices::getInstance()->getConnectionProvider();
72    }
73
74    /**
75     * @return never
76     */
77    protected function assertWritableRepo() {
78        throw new LogicException( static::class . ': write operations are not supported.' );
79    }
80
81    public function getInfo() {
82        return FileRepo::getInfo();
83    }
84}