Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
BlockUtilsFactory
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getBlockUtils
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
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
22namespace MediaWiki\Block;
23
24use MediaWiki\Config\ServiceOptions;
25use MediaWiki\User\ActorStoreFactory;
26use MediaWiki\User\UserNameUtils;
27use Wikimedia\Rdbms\LBFactory;
28
29/**
30 * @since 1.42
31 */
32class BlockUtilsFactory {
33    /**
34     * @internal For use by ServiceWiring
35     */
36    public const CONSTRUCTOR_OPTIONS = BlockUtils::CONSTRUCTOR_OPTIONS;
37
38    /** @var ServiceOptions */
39    private $options;
40
41    /** @var ActorStoreFactory */
42    private $actorStoreFactory;
43
44    /** @var UserNameUtils */
45    private $userNameUtils;
46
47    /** @var BlockUtils[] */
48    private $storeCache;
49
50    /** @var LBFactory */
51    private $loadBalancerFactory;
52
53    /**
54     * @param ServiceOptions $options
55     * @param ActorStoreFactory $actorStoreFactory
56     * @param UserNameUtils $userNameUtils
57     * @param LBFactory $loadBalancerFactory
58     */
59    public function __construct(
60        ServiceOptions $options,
61        ActorStoreFactory $actorStoreFactory,
62        UserNameUtils $userNameUtils,
63        LBFactory $loadBalancerFactory
64    ) {
65        $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
66
67        $this->options = $options;
68        $this->actorStoreFactory = $actorStoreFactory;
69        $this->userNameUtils = $userNameUtils;
70        $this->loadBalancerFactory = $loadBalancerFactory;
71    }
72
73    /**
74     * @param string|false $wikiId
75     * @return BlockUtils
76     */
77    public function getBlockUtils( $wikiId = Block::LOCAL ): BlockUtils {
78        if ( is_string( $wikiId ) && $this->loadBalancerFactory->getLocalDomainID() === $wikiId ) {
79            $wikiId = Block::LOCAL;
80        }
81
82        $storeCacheKey = $wikiId === Block::LOCAL ? 'LOCAL' : 'crosswikistore-' . $wikiId;
83        if ( !isset( $this->storeCache[$storeCacheKey] ) ) {
84            $this->storeCache[$storeCacheKey] = new BlockUtils(
85                $this->options,
86                $this->actorStoreFactory->getUserIdentityLookup( $wikiId ),
87                $this->userNameUtils,
88                $wikiId
89            );
90        }
91        return $this->storeCache[$storeCacheKey];
92    }
93}