Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LockManagerGroupFactory
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLockManagerGroup
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace MediaWiki\FileBackend\LockManager;
4
5use LockManagerGroup;
6
7/**
8 * Service to construct LockManagerGroups.
9 */
10class LockManagerGroupFactory {
11    /** @var string */
12    private $defaultDomain;
13
14    /** @var array */
15    private $lockManagerConfigs;
16
17    /** @var LockManagerGroup[] (domain => LockManagerGroup) */
18    private $instances = [];
19
20    /**
21     * Do not call directly, use MediaWikiServices.
22     *
23     * @param string $defaultDomain
24     * @param array $lockManagerConfigs In format of $wgLockManagers
25     */
26    public function __construct( $defaultDomain, array $lockManagerConfigs ) {
27        $this->defaultDomain = $defaultDomain;
28        $this->lockManagerConfigs = $lockManagerConfigs;
29    }
30
31    /**
32     * @param string|null|false $domain Domain (usually wiki ID). false for the default (normally
33     *   the current wiki's domain).
34     * @return LockManagerGroup
35     */
36    public function getLockManagerGroup( $domain = false ): LockManagerGroup {
37        if ( $domain === false || $domain === null ) {
38            $domain = $this->defaultDomain;
39        }
40
41        if ( !isset( $this->instances[$domain] ) ) {
42            $this->instances[$domain] =
43                new LockManagerGroup( $domain, $this->lockManagerConfigs );
44        }
45
46        return $this->instances[$domain];
47    }
48}