One small change that was supposed to be in 5a6c18a086 but didn't make
it into the patch version that got merged, and removal of some long-dead
code.
phan objected to the use of new $class without being explicitly
reassured that $class is, in fact, a string. I don't know why.
Change-Id: Ifa00c59ab4464109414f21db37e3a6db21decdf3
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\FileBackend\LockManager;
|
|
|
|
use LockManagerGroup;
|
|
use Wikimedia\Rdbms\LBFactory;
|
|
|
|
/**
|
|
* Service to construct LockManagerGroups.
|
|
*/
|
|
class LockManagerGroupFactory {
|
|
/** @var string */
|
|
private $defaultDomain;
|
|
|
|
/** @var array */
|
|
private $lockManagerConfigs;
|
|
|
|
/** @var LBFactory */
|
|
private $lbFactory;
|
|
|
|
/** @var LockManagerGroup[] (domain => LockManagerGroup) */
|
|
private $instances = [];
|
|
|
|
/**
|
|
* Do not call directly, use MediaWikiServices.
|
|
*
|
|
* @param string $defaultDomain
|
|
* @param array $lockManagerConfigs In format of $wgLockManagers
|
|
* @param LBFactory $lbFactory
|
|
*/
|
|
public function __construct( $defaultDomain, array $lockManagerConfigs, LBFactory $lbFactory ) {
|
|
$this->defaultDomain = $defaultDomain;
|
|
$this->lockManagerConfigs = $lockManagerConfigs;
|
|
$this->lbFactory = $lbFactory;
|
|
}
|
|
|
|
/**
|
|
* @param string|null|false $domain Domain (usually wiki ID). false for the default (normally
|
|
* the current wiki's domain).
|
|
* @return LockManagerGroup
|
|
*/
|
|
public function getLockManagerGroup( $domain = false ) : LockManagerGroup {
|
|
if ( $domain === false || $domain === null ) {
|
|
$domain = $this->defaultDomain;
|
|
}
|
|
|
|
if ( !isset( $this->instances[$domain] ) ) {
|
|
$this->instances[$domain] =
|
|
new LockManagerGroup( $domain, $this->lockManagerConfigs, $this->lbFactory );
|
|
}
|
|
|
|
return $this->instances[$domain];
|
|
}
|
|
}
|