MediaWiki REL1_40
LockManagerGroup.php
Go to the documentation of this file.
1<?php
24
33 protected $domain;
34
36 protected $managers = [];
37
44 public function __construct( $domain, array $lockManagerConfigs ) {
45 $this->domain = $domain;
46
47 foreach ( $lockManagerConfigs as $config ) {
48 $config['domain'] = $this->domain;
49 if ( !isset( $config['name'] ) ) {
50 throw new Exception( "Cannot register a lock manager with no name." );
51 }
52 $name = $config['name'];
53 if ( !isset( $config['class'] ) ) {
54 throw new Exception( "Cannot register lock manager `{$name}` with no class." );
55 }
56 $class = $config['class'];
57 unset( $config['class'] ); // lock manager won't need this
58 $this->managers[$name] = [
59 'class' => $class,
60 'config' => $config,
61 'instance' => null
62 ];
63 }
64 }
65
73 public function get( $name ) {
74 if ( !isset( $this->managers[$name] ) ) {
75 throw new Exception( "No lock manager defined with the name `$name`." );
76 }
77 // Lazy-load the actual lock manager instance
78 if ( !isset( $this->managers[$name]['instance'] ) ) {
79 $class = $this->managers[$name]['class'];
80 '@phan-var string $class';
81 $config = $this->managers[$name]['config'];
82 $config['logger'] = LoggerFactory::getInstance( 'LockManager' );
83
84 $this->managers[$name]['instance'] = new $class( $config );
85 }
86
87 return $this->managers[$name]['instance'];
88 }
89
97 public function config( $name ) {
98 if ( !isset( $this->managers[$name] ) ) {
99 throw new Exception( "No lock manager defined with the name `$name`." );
100 }
101 $class = $this->managers[$name]['class'];
102
103 return [ 'class' => $class ] + $this->managers[$name]['config'];
104 }
105
114 public function getDefault() {
115 wfDeprecated( __METHOD__, '1.35' );
116
117 return isset( $this->managers['default'] )
118 ? $this->get( 'default' )
119 : new NullLockManager( [] );
120 }
121
132 public function getAny() {
133 wfDeprecated( __METHOD__, '1.35' );
134
135 return isset( $this->managers['default'] )
136 ? $this->get( 'default' )
137 : $this->get( 'fsLockManager' );
138 }
139}
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.
__construct( $domain, array $lockManagerConfigs)
Do not call this directly.
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...
array $managers
Array of (name => ('class' => ..., 'config' => ..., 'instance' => ...))
PSR-3 logger instance factory.
Simple lock management based on in-process reference counting.