wiki.techinc.nl/includes/filebackend/lockmanager/LockManagerGroupFactory.php
Timo Tijhof bfd419fb9e filebackend: Remove LBFactory dep from LockManager service
This was added during the conversation to a service class in
commit 5a6c18a086 (Iaa7354f31), but the code it was for is unused
and was shortly after removed in commit 37022e2e (Ifa00c59ab), thus
leaving this unused dependency behind.

The motiviation for this change is that Parser is used during
the installer (maintenance/install.php) with DB services naturally
disabled, and Parser has the dependency chain Parser -> BadFileLookup
-> RepoGroup (hidden) -> FileBackendGroup -> LockManagerGroup.

Solving the hidden part is proposed in I9de42a26cd, but fails as
LockManagerGroup currently depends on LBFactory which makes
it crash in db-less environments.

Change-Id: Icaad0acbed2957c1f86e4089dd221a8cdcb1a1ae
2022-08-02 22:22:48 -07:00

48 lines
1.2 KiB
PHP

<?php
namespace MediaWiki\FileBackend\LockManager;
use LockManagerGroup;
/**
* Service to construct LockManagerGroups.
*/
class LockManagerGroupFactory {
/** @var string */
private $defaultDomain;
/** @var array */
private $lockManagerConfigs;
/** @var LockManagerGroup[] (domain => LockManagerGroup) */
private $instances = [];
/**
* Do not call directly, use MediaWikiServices.
*
* @param string $defaultDomain
* @param array $lockManagerConfigs In format of $wgLockManagers
*/
public function __construct( $defaultDomain, array $lockManagerConfigs ) {
$this->defaultDomain = $defaultDomain;
$this->lockManagerConfigs = $lockManagerConfigs;
}
/**
* @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 );
}
return $this->instances[$domain];
}
}