24use Wikimedia\Assert\Assert;
37 protected $factoryFunctions = [];
44 protected $configs = [];
52 return \MediaWiki\MediaWikiServices::getInstance()->getConfigFactory();
67 Assert::parameterType( self::class, $other,
'$other' );
70 foreach ( $other->factoryFunctions as $name => $otherFunc ) {
71 if ( !isset( $this->factoryFunctions[$name] ) ) {
77 if ( isset( $other->configs[$name] )
78 && $this->factoryFunctions[$name] == $otherFunc
80 $this->configs[
$name] = $other->configs[
$name];
81 unset( $other->configs[$name] );
86 $other->factoryFunctions = [];
94 return array_keys( $this->factoryFunctions );
106 public function register(
$name, $callback ) {
107 if ( !is_callable( $callback ) && !( $callback instanceof
Config ) ) {
108 if ( is_array( $callback ) ) {
109 $callback =
'[ ' . implode(
', ', $callback ) .
' ]';
110 } elseif ( is_object( $callback ) ) {
111 $callback =
'instanceof ' . get_class( $callback );
113 throw new InvalidArgumentException(
'Invalid callback \'' . $callback .
'\' provided
' );
116 unset( $this->configs[$name] );
117 $this->factoryFunctions[$name] = $callback;
129 public function makeConfig( $name ) {
130 if ( !isset( $this->configs[$name] ) ) {
132 if ( !isset( $this->factoryFunctions[$key] ) ) {
135 if ( !isset( $this->factoryFunctions[$key] ) ) {
136 throw new ConfigException( "No registered builder available for $name." );
139 if ( $this->factoryFunctions[$key] instanceof Config ) {
140 $conf = $this->factoryFunctions[$key];
142 $conf = call_user_func( $this->factoryFunctions[$key], $this );
145 if ( $conf instanceof Config ) {
146 $this->configs[$name] = $conf;
148 throw new UnexpectedValueException( "The builder for $name returned a non-Config object." );
152 return $this->configs[$name];
Factory class to create Config objects.
static getDefaultInstance()
salvage(SalvageableService $other)
Re-uses existing Cache objects from $other.
array $factoryFunctions
Map of config name => callback.
array $configs
Config objects that have already been created name => Config object.
Allows to change the fields on the form that will be generated $name
Interface for configuration instances.