MediaWiki
REL1_19
|
00001 <?php 00009 class LockManagerGroup { 00010 00014 protected static $instance = null; 00015 00017 protected $managers = array(); 00018 00019 protected function __construct() {} 00020 protected function __clone() {} 00021 00025 public static function singleton() { 00026 if ( self::$instance == null ) { 00027 self::$instance = new self(); 00028 self::$instance->initFromGlobals(); 00029 } 00030 return self::$instance; 00031 } 00032 00038 protected function initFromGlobals() { 00039 global $wgLockManagers; 00040 00041 $this->register( $wgLockManagers ); 00042 } 00043 00051 protected function register( array $configs ) { 00052 foreach ( $configs as $config ) { 00053 if ( !isset( $config['name'] ) ) { 00054 throw new MWException( "Cannot register a lock manager with no name." ); 00055 } 00056 $name = $config['name']; 00057 if ( !isset( $config['class'] ) ) { 00058 throw new MWException( "Cannot register lock manager `{$name}` with no class." ); 00059 } 00060 $class = $config['class']; 00061 unset( $config['class'] ); // lock manager won't need this 00062 $this->managers[$name] = array( 00063 'class' => $class, 00064 'config' => $config, 00065 'instance' => null 00066 ); 00067 } 00068 } 00069 00077 public function get( $name ) { 00078 if ( !isset( $this->managers[$name] ) ) { 00079 throw new MWException( "No lock manager defined with the name `$name`." ); 00080 } 00081 // Lazy-load the actual lock manager instance 00082 if ( !isset( $this->managers[$name]['instance'] ) ) { 00083 $class = $this->managers[$name]['class']; 00084 $config = $this->managers[$name]['config']; 00085 $this->managers[$name]['instance'] = new $class( $config ); 00086 } 00087 return $this->managers[$name]['instance']; 00088 } 00089 }