3 * Class to handle file lock manager registration
7 class LockManagerGroup
{
8 protected static $instance = null;
10 /** @var Array of (name => ('class' =>, 'config' =>, 'instance' =>)) */
11 protected $managers = array();
13 protected function __construct() {}
14 protected function __clone() {}
16 public static function singleton() {
17 if ( self
::$instance == null ) {
18 self
::$instance = new self();
20 return self
::$instance;
24 * Register an array of file lock manager configurations
26 * @param $configs Array
30 public function register( array $configs ) {
31 foreach ( $configs as $config ) {
32 if ( !isset( $config['name'] ) ) {
33 throw new MWException( "Cannot register a lock manager with no name." );
35 $name = $config['name'];
36 if ( !isset( $config['class'] ) ) {
37 throw new MWException( "Cannot register lock manager `{$name}` with no class." );
39 $class = $config['class'];
40 unset( $config['class'] ); // lock manager won't need this
41 $this->managers
[$name] = array(
50 * Get the lock manager object with a given name
56 public function get( $name ) {
57 if ( !isset( $this->managers
[$name] ) ) {
58 throw new MWException( "No lock manager defined with the name `$name`." );
60 // Lazy-load the actual lock manager instance
61 if ( !isset( $this->managers
[$name]['instance'] ) ) {
62 $class = $this->managers
[$name]['class'];
63 $config = $this->managers
[$name]['config'];
64 $this->managers
[$name]['instance'] = new $class( $config );
66 return $this->managers
[$name]['instance'];