24use Wikimedia\Assert\Assert;
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 throw new InvalidArgumentException(
'Invalid callback provided' );
111 unset( $this->configs[$name] );
112 $this->factoryFunctions[
$name] = $callback;
125 if ( !isset( $this->configs[$name] ) ) {
127 if ( !isset( $this->factoryFunctions[$key] ) ) {
130 if ( !isset( $this->factoryFunctions[$key] ) ) {
131 throw new ConfigException(
"No registered builder available for $name." );
134 if ( $this->factoryFunctions[$key] instanceof Config ) {
135 $conf = $this->factoryFunctions[$key];
137 $conf = call_user_func( $this->factoryFunctions[$key], $this );
140 if ( $conf instanceof Config ) {
141 $this->configs[
$name] = $conf;
143 throw new UnexpectedValueException(
"The builder for $name returned a non-Config object." );
147 return $this->configs[
$name];
Exceptions for config failures.
Factory class to create Config objects.
static getDefaultInstance()
makeConfig( $name)
Create a given Config using the registered callback for $name.
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