MediaWiki
REL1_23
|
00001 <?php 00002 00029 class ConfigFactory { 00030 00035 protected $factoryFunctions = array(); 00036 00042 protected $configs = array(); 00043 00044 public static function getDefaultInstance() { 00045 static $self = null; 00046 if ( !$self ) { 00047 $self = new self; 00048 global $wgConfigRegistry; 00049 foreach ( $wgConfigRegistry as $name => $callback ) { 00050 $self->register( $name, $callback ); 00051 } 00052 } 00053 return $self; 00054 } 00055 00063 public function register( $name, $callback ) { 00064 if ( !is_callable( $callback ) ) { 00065 throw new InvalidArgumentException( 'Invalid callback provided' ); 00066 } 00067 $this->factoryFunctions[$name] = $callback; 00068 } 00069 00079 public function makeConfig( $name ) { 00080 if ( !isset( $this->configs[$name] ) ) { 00081 if ( !isset( $this->factoryFunctions[$name] ) ) { 00082 throw new ConfigException( "No registered builder available for $name." ); 00083 } 00084 $conf = call_user_func( $this->factoryFunctions[$name], $this ); 00085 if ( $conf instanceof Config ) { 00086 $this->configs[$name] = $conf; 00087 } else { 00088 throw new UnexpectedValueException( "The builder for $name returned a non-Config object." ); 00089 } 00090 } 00091 00092 return $this->configs[$name]; 00093 } 00094 }