5e533667e79eb0758ab8a1a2fa9f6cf92f4a0054
3 * Class to handle file lock manager registration
9 class LockManagerGroup
{
12 * @var LockManagerGroup
14 protected static $instance = null;
16 /** @var Array of (name => ('class' =>, 'config' =>, 'instance' =>)) */
17 protected $managers = array();
19 protected function __construct() {}
20 protected function __clone() {}
23 * @return LockManagerGroup
25 public static function singleton() {
26 if ( self
::$instance == null ) {
27 self
::$instance = new self();
28 self
::$instance->initFromGlobals();
30 return self
::$instance;
34 * Destroy the singleton instance, so that a new one will be created next
35 * time singleton() is called.
37 public static function destroySingleton() {
38 self
::$instance = null;
42 * Register lock managers from the global variables
46 protected function initFromGlobals() {
47 global $wgLockManagers;
49 $this->register( $wgLockManagers );
53 * Register an array of file lock manager configurations
55 * @param $configs Array
59 protected function register( array $configs ) {
60 foreach ( $configs as $config ) {
61 if ( !isset( $config['name'] ) ) {
62 throw new MWException( "Cannot register a lock manager with no name." );
64 $name = $config['name'];
65 if ( !isset( $config['class'] ) ) {
66 throw new MWException( "Cannot register lock manager `{$name}` with no class." );
68 $class = $config['class'];
69 unset( $config['class'] ); // lock manager won't need this
70 $this->managers
[$name] = array(
79 * Get the lock manager object with a given name
85 public function get( $name ) {
86 if ( !isset( $this->managers
[$name] ) ) {
87 throw new MWException( "No lock manager defined with the name `$name`." );
89 // Lazy-load the actual lock manager instance
90 if ( !isset( $this->managers
[$name]['instance'] ) ) {
91 $class = $this->managers
[$name]['class'];
92 $config = $this->managers
[$name]['config'];
93 $this->managers
[$name]['instance'] = new $class( $config );
95 return $this->managers
[$name]['instance'];