Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
BlockRestrictionStoreFactory | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
6.02 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getBlockRestrictionStore | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
5.03 |
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 | |
21 | namespace MediaWiki\Block; |
22 | |
23 | use MediaWiki\DAO\WikiAwareEntity; |
24 | use Wikimedia\Rdbms\LBFactory; |
25 | |
26 | /** |
27 | * @author Zabe |
28 | * |
29 | * @since 1.38 |
30 | */ |
31 | class BlockRestrictionStoreFactory { |
32 | /** @var LBFactory */ |
33 | private $loadBalancerFactory; |
34 | |
35 | /** @var BlockRestrictionStore[] */ |
36 | private $storeCache = []; |
37 | |
38 | /** @var int */ |
39 | private $blockTargetMigrationStage; |
40 | |
41 | /** |
42 | * @param LBFactory $loadBalancerFactory |
43 | * @param int $blockTargetMigrationStage |
44 | */ |
45 | public function __construct( |
46 | LBFactory $loadBalancerFactory, |
47 | $blockTargetMigrationStage |
48 | ) { |
49 | $this->loadBalancerFactory = $loadBalancerFactory; |
50 | $this->blockTargetMigrationStage = $blockTargetMigrationStage; |
51 | } |
52 | |
53 | /** |
54 | * @param string|false $wikiId |
55 | * @return BlockRestrictionStore |
56 | */ |
57 | public function getBlockRestrictionStore( $wikiId = WikiAwareEntity::LOCAL ): BlockRestrictionStore { |
58 | if ( is_string( $wikiId ) && $this->loadBalancerFactory->getLocalDomainID() === $wikiId ) { |
59 | $wikiId = WikiAwareEntity::LOCAL; |
60 | } |
61 | |
62 | $storeCacheKey = $wikiId === WikiAwareEntity::LOCAL ? 'LOCAL' : 'crosswikistore-' . $wikiId; |
63 | if ( !isset( $this->storeCache[$storeCacheKey] ) ) { |
64 | $this->storeCache[$storeCacheKey] = new BlockRestrictionStore( |
65 | $this->loadBalancerFactory, |
66 | $this->blockTargetMigrationStage, |
67 | $wikiId |
68 | ); |
69 | } |
70 | return $this->storeCache[$storeCacheKey]; |
71 | } |
72 | } |