MediaWiki REL1_37
LockManagerGroup.php
Go to the documentation of this file.
1<?php
26
35 protected $domain;
36
38 protected $lbFactory;
39
41 protected $managers = [];
42
50 public function __construct( $domain, array $lockManagerConfigs, LBFactory $lbFactory ) {
51 $this->domain = $domain;
52 $this->lbFactory = $lbFactory;
53
54 foreach ( $lockManagerConfigs as $config ) {
55 $config['domain'] = $this->domain;
56 if ( !isset( $config['name'] ) ) {
57 throw new Exception( "Cannot register a lock manager with no name." );
58 }
59 $name = $config['name'];
60 if ( !isset( $config['class'] ) ) {
61 throw new Exception( "Cannot register lock manager `{$name}` with no class." );
62 }
63 $class = $config['class'];
64 unset( $config['class'] ); // lock manager won't need this
65 $this->managers[$name] = [
66 'class' => $class,
67 'config' => $config,
68 'instance' => null
69 ];
70 }
71 }
72
79 public static function singleton( $domain = false ) {
80 wfDeprecated( __METHOD__, '1.34' );
81 return MediaWikiServices::getInstance()->getLockManagerGroupFactory()
82 ->getLockManagerGroup( $domain );
83 }
84
91 public static function destroySingletons() {
92 wfDeprecated( __METHOD__, '1.34' );
93 MediaWikiServices::getInstance()->resetServiceForTesting( 'LockManagerGroupFactory' );
94 }
95
103 public function get( $name ) {
104 if ( !isset( $this->managers[$name] ) ) {
105 throw new Exception( "No lock manager defined with the name `$name`." );
106 }
107 // Lazy-load the actual lock manager instance
108 if ( !isset( $this->managers[$name]['instance'] ) ) {
109 $class = $this->managers[$name]['class'];
110 '@phan-var string $class';
111 $config = $this->managers[$name]['config'];
112 $config['logger'] = LoggerFactory::getInstance( 'LockManager' );
113
114 $this->managers[$name]['instance'] = new $class( $config );
115 }
116
117 return $this->managers[$name]['instance'];
118 }
119
127 public function config( $name ) {
128 if ( !isset( $this->managers[$name] ) ) {
129 throw new Exception( "No lock manager defined with the name `$name`." );
130 }
131 $class = $this->managers[$name]['class'];
132
133 return [ 'class' => $class ] + $this->managers[$name]['config'];
134 }
135
144 public function getDefault() {
145 wfDeprecated( __METHOD__, '1.35' );
146
147 return isset( $this->managers['default'] )
148 ? $this->get( 'default' )
149 : new NullLockManager( [] );
150 }
151
162 public function getAny() {
163 wfDeprecated( __METHOD__, '1.35' );
164
165 return isset( $this->managers['default'] )
166 ? $this->get( 'default' )
167 : $this->get( 'fsLockManager' );
168 }
169}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Class to handle file lock manager registration.
getDefault()
Get the default lock manager configured for the site.
string $domain
domain (usually wiki ID)
config( $name)
Get the config array for a lock manager object with a given name.
getAny()
Get the default lock manager configured for the site or at least some other effective configured lock...
static singleton( $domain=false)
static destroySingletons()
Destroy the singleton instances.
array $managers
Array of (name => ('class' => ..., 'config' => ..., 'instance' => ...))
__construct( $domain, array $lockManagerConfigs, LBFactory $lbFactory)
Do not call this directly.
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Simple version of LockManager that only does lock reference counting.
An interface for generating database load balancers.
Definition LBFactory.php:42