MediaWiki  master
LockManagerGroup.php
Go to the documentation of this file.
1 <?php
25 
34  protected $domain;
35 
37  protected $lbFactory;
38 
40  protected $managers = [];
41 
49  public function __construct( $domain, array $lockManagerConfigs, LBFactory $lbFactory ) {
50  $this->domain = $domain;
51  $this->lbFactory = $lbFactory;
52 
53  foreach ( $lockManagerConfigs as $config ) {
54  $config['domain'] = $this->domain;
55  if ( !isset( $config['name'] ) ) {
56  throw new Exception( "Cannot register a lock manager with no name." );
57  }
58  $name = $config['name'];
59  if ( !isset( $config['class'] ) ) {
60  throw new Exception( "Cannot register lock manager `{$name}` with no class." );
61  }
62  $class = $config['class'];
63  unset( $config['class'] ); // lock manager won't need this
64  $this->managers[$name] = [
65  'class' => $class,
66  'config' => $config,
67  'instance' => null
68  ];
69  }
70  }
71 
79  public function get( $name ) {
80  if ( !isset( $this->managers[$name] ) ) {
81  throw new Exception( "No lock manager defined with the name `$name`." );
82  }
83  // Lazy-load the actual lock manager instance
84  if ( !isset( $this->managers[$name]['instance'] ) ) {
85  $class = $this->managers[$name]['class'];
86  '@phan-var string $class';
87  $config = $this->managers[$name]['config'];
88  $config['logger'] = LoggerFactory::getInstance( 'LockManager' );
89 
90  $this->managers[$name]['instance'] = new $class( $config );
91  }
92 
93  return $this->managers[$name]['instance'];
94  }
95 
103  public function config( $name ) {
104  if ( !isset( $this->managers[$name] ) ) {
105  throw new Exception( "No lock manager defined with the name `$name`." );
106  }
107  $class = $this->managers[$name]['class'];
108 
109  return [ 'class' => $class ] + $this->managers[$name]['config'];
110  }
111 
120  public function getDefault() {
121  wfDeprecated( __METHOD__, '1.35' );
122 
123  return isset( $this->managers['default'] )
124  ? $this->get( 'default' )
125  : new NullLockManager( [] );
126  }
127 
138  public function getAny() {
139  wfDeprecated( __METHOD__, '1.35' );
140 
141  return isset( $this->managers['default'] )
142  ? $this->get( 'default' )
143  : $this->get( 'fsLockManager' );
144  }
145 }
LockManagerGroup\__construct
__construct( $domain, array $lockManagerConfigs, LBFactory $lbFactory)
Do not call this directly.
Definition: LockManagerGroup.php:49
LockManagerGroup\getAny
getAny()
Get the default lock manager configured for the site or at least some other effective configured lock...
Definition: LockManagerGroup.php:138
LockManagerGroup\$domain
string $domain
domain (usually wiki ID)
Definition: LockManagerGroup.php:34
NullLockManager
Simple version of LockManager that only does lock reference counting.
Definition: NullLockManager.php:28
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
LockManagerGroup
Class to handle file lock manager registration.
Definition: LockManagerGroup.php:32
LockManagerGroup\$lbFactory
LBFactory $lbFactory
Definition: LockManagerGroup.php:37
LockManagerGroup\config
config( $name)
Get the config array for a lock manager object with a given name.
Definition: LockManagerGroup.php:103
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:42
LockManagerGroup\getDefault
getDefault()
Get the default lock manager configured for the site.
Definition: LockManagerGroup.php:120
LockManagerGroup\$managers
array $managers
Array of (name => ('class' => ..., 'config' => ..., 'instance' => ...))
Definition: LockManagerGroup.php:40