MediaWiki
REL1_20
|
00001 <?php 00031 class LockManagerGroup { 00035 protected static $instance = null; 00036 00038 protected $managers = array(); 00039 00040 protected function __construct() {} 00041 00045 public static function singleton() { 00046 if ( self::$instance == null ) { 00047 self::$instance = new self(); 00048 self::$instance->initFromGlobals(); 00049 } 00050 return self::$instance; 00051 } 00052 00057 public static function destroySingleton() { 00058 self::$instance = null; 00059 } 00060 00066 protected function initFromGlobals() { 00067 global $wgLockManagers; 00068 00069 $this->register( $wgLockManagers ); 00070 } 00071 00079 protected function register( array $configs ) { 00080 foreach ( $configs as $config ) { 00081 if ( !isset( $config['name'] ) ) { 00082 throw new MWException( "Cannot register a lock manager with no name." ); 00083 } 00084 $name = $config['name']; 00085 if ( !isset( $config['class'] ) ) { 00086 throw new MWException( "Cannot register lock manager `{$name}` with no class." ); 00087 } 00088 $class = $config['class']; 00089 unset( $config['class'] ); // lock manager won't need this 00090 $this->managers[$name] = array( 00091 'class' => $class, 00092 'config' => $config, 00093 'instance' => null 00094 ); 00095 } 00096 } 00097 00105 public function get( $name ) { 00106 if ( !isset( $this->managers[$name] ) ) { 00107 throw new MWException( "No lock manager defined with the name `$name`." ); 00108 } 00109 // Lazy-load the actual lock manager instance 00110 if ( !isset( $this->managers[$name]['instance'] ) ) { 00111 $class = $this->managers[$name]['class']; 00112 $config = $this->managers[$name]['config']; 00113 $this->managers[$name]['instance'] = new $class( $config ); 00114 } 00115 return $this->managers[$name]['instance']; 00116 } 00117 00124 public function getDefault() { 00125 return isset( $this->managers['default'] ) 00126 ? $this->get( 'default' ) 00127 : new NullLockManager( array() ); 00128 } 00129 00138 public function getAny() { 00139 return isset( $this->managers['default'] ) 00140 ? $this->get( 'default' ) 00141 : $this->get( 'fsLockManager' ); 00142 } 00143 }