Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
BlockUtilsFactory | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getBlockUtils | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | * |
19 | * @file |
20 | */ |
21 | |
22 | namespace MediaWiki\Block; |
23 | |
24 | use MediaWiki\Config\ServiceOptions; |
25 | use MediaWiki\User\ActorStoreFactory; |
26 | use MediaWiki\User\UserNameUtils; |
27 | use Wikimedia\Rdbms\LBFactory; |
28 | |
29 | /** |
30 | * @since 1.42 |
31 | */ |
32 | class BlockUtilsFactory { |
33 | /** |
34 | * @internal For use by ServiceWiring |
35 | */ |
36 | public const CONSTRUCTOR_OPTIONS = BlockUtils::CONSTRUCTOR_OPTIONS; |
37 | |
38 | private ServiceOptions $options; |
39 | private ActorStoreFactory $actorStoreFactory; |
40 | private UserNameUtils $userNameUtils; |
41 | private LBFactory $loadBalancerFactory; |
42 | |
43 | /** @var BlockUtils[] */ |
44 | private array $storeCache = []; |
45 | |
46 | public function __construct( |
47 | ServiceOptions $options, |
48 | ActorStoreFactory $actorStoreFactory, |
49 | UserNameUtils $userNameUtils, |
50 | LBFactory $loadBalancerFactory |
51 | ) { |
52 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
53 | |
54 | $this->options = $options; |
55 | $this->actorStoreFactory = $actorStoreFactory; |
56 | $this->userNameUtils = $userNameUtils; |
57 | $this->loadBalancerFactory = $loadBalancerFactory; |
58 | } |
59 | |
60 | /** |
61 | * @param string|false $wikiId |
62 | * @return BlockUtils |
63 | */ |
64 | public function getBlockUtils( $wikiId = Block::LOCAL ): BlockUtils { |
65 | if ( is_string( $wikiId ) && $this->loadBalancerFactory->getLocalDomainID() === $wikiId ) { |
66 | $wikiId = Block::LOCAL; |
67 | } |
68 | |
69 | $storeCacheKey = $wikiId === Block::LOCAL ? 'LOCAL' : 'crosswikistore-' . $wikiId; |
70 | if ( !isset( $this->storeCache[$storeCacheKey] ) ) { |
71 | $this->storeCache[$storeCacheKey] = new BlockUtils( |
72 | $this->options, |
73 | $this->actorStoreFactory->getUserIdentityLookup( $wikiId ), |
74 | $this->userNameUtils, |
75 | $wikiId |
76 | ); |
77 | } |
78 | return $this->storeCache[$storeCacheKey]; |
79 | } |
80 | } |