23 use Wikimedia\Assert\Assert;
52 return \MediaWiki\MediaWikiServices::getInstance()->getConfigFactory();
67 Assert::parameterType( self::class, $other,
'$other' );
70 '@phan-var self $other';
71 foreach ( $other->factoryFunctions as $name => $otherFunc ) {
72 if ( !isset( $this->factoryFunctions[$name] ) ) {
78 if ( isset( $other->configs[$name] )
79 && $this->factoryFunctions[$name] == $otherFunc
81 $this->configs[$name] = $other->configs[$name];
82 unset( $other->configs[$name] );
87 $other->factoryFunctions = [];
95 return array_keys( $this->factoryFunctions );
107 public function register( $name, $callback ) {
108 if ( !is_callable( $callback ) && !( $callback instanceof
Config ) ) {
109 if ( is_array( $callback ) ) {
110 $callback =
'[ ' . implode(
', ', $callback ) .
' ]';
111 } elseif ( is_object( $callback ) ) {
112 $callback =
'instanceof ' . get_class( $callback );
114 throw new InvalidArgumentException(
'Invalid callback \'' . $callback .
'\' provided
' );
117 unset( $this->configs[$name] );
118 $this->factoryFunctions[$name] = $callback;
130 public function makeConfig( $name ) {
131 if ( !isset( $this->configs[$name] ) ) {
133 if ( !isset( $this->factoryFunctions[$key] ) ) {
136 if ( !isset( $this->factoryFunctions[$key] ) ) {
137 throw new ConfigException( "No registered builder available for $name." );
140 if ( $this->factoryFunctions[$key] instanceof Config ) {
141 $conf = $this->factoryFunctions[$key];
143 $conf = call_user_func( $this->factoryFunctions[$key], $this );
146 if ( $conf instanceof Config ) {
147 $this->configs[$name] = $conf;
149 throw new UnexpectedValueException( "The builder for $name returned a non-Config object." );
153 return $this->configs[$name];