MediaWiki master
LockManagerGroup.php
Go to the documentation of this file.
1<?php
11
12use Exception;
13use InvalidArgumentException;
16
25 protected $domain;
26
28 protected $managers = [];
29
36 public function __construct( $domain, array $lockManagerConfigs ) {
37 $this->domain = $domain;
38
39 foreach ( $lockManagerConfigs as $config ) {
40 $config['domain'] = $this->domain;
41 if ( !isset( $config['name'] ) ) {
42 throw new InvalidArgumentException( "Cannot register a lock manager with no name." );
43 }
44 $name = $config['name'];
45 if ( !isset( $config['class'] ) ) {
46 throw new InvalidArgumentException( "Cannot register lock manager `{$name}` with no class." );
47 }
48 $class = $config['class'];
49 unset( $config['class'] ); // lock manager won't need this
50 $this->managers[$name] = [
51 'class' => $class,
52 'config' => $config,
53 'instance' => null
54 ];
55 }
56 }
57
65 public function get( $name ) {
66 if ( !isset( $this->managers[$name] ) ) {
67 throw new InvalidArgumentException( "No lock manager defined with the name `$name`." );
68 }
69 // Lazy-load the actual lock manager instance
70 if ( !isset( $this->managers[$name]['instance'] ) ) {
71 $class = $this->managers[$name]['class'];
72 '@phan-var class-string<LockManager> $class';
73 $config = $this->managers[$name]['config'];
74 $config['logger'] = LoggerFactory::getInstance( 'LockManager' );
75
76 $this->managers[$name]['instance'] = new $class( $config );
77 }
78
79 return $this->managers[$name]['instance'];
80 }
81
89 public function config( $name ) {
90 if ( !isset( $this->managers[$name] ) ) {
91 throw new InvalidArgumentException( "No lock manager defined with the name `$name`." );
92 }
93 $class = $this->managers[$name]['class'];
94
95 return [ 'class' => $class ] + $this->managers[$name]['config'];
96 }
97}
Class to handle file lock manager registration.
array $managers
Array of (name => ('class' => ..., 'config' => ..., 'instance' => ...))
config( $name)
Get the config array for a lock manager object with a given name.
__construct( $domain, array $lockManagerConfigs)
Do not call this directly.
Create PSR-3 logger objects.
Resource locking handling.