26use InvalidArgumentException;
28use UnexpectedValueException;
29use Wikimedia\Assert\Assert;
30use Wikimedia\Services\SalvageableService;
74 public function salvage( SalvageableService $other ) {
75 Assert::parameterType( self::class, $other,
'$other' );
78 '@phan-var self $other';
79 foreach ( $other->factoryFunctions as $name => $otherFunc ) {
80 if ( !isset( $this->factoryFunctions[$name] ) ) {
86 if ( isset( $other->configs[$name] )
87 && $this->factoryFunctions[$name] == $otherFunc
89 $this->configs[$name] = $other->configs[$name];
90 unset( $other->configs[$name] );
95 $other->factoryFunctions = [];
103 return array_keys( $this->factoryFunctions );
115 public function register( $name, $callback ) {
116 if ( !is_callable( $callback ) && !( $callback instanceof
Config ) ) {
117 if ( is_array( $callback ) ) {
118 $callback =
'[ ' . implode(
', ', $callback ) .
' ]';
119 } elseif ( is_object( $callback ) ) {
120 $callback =
'instanceof ' . get_class( $callback );
122 throw new InvalidArgumentException(
'Invalid callback \'' . $callback .
'\' provided
' );
125 unset( $this->configs[$name] );
126 $this->factoryFunctions[$name] = $callback;
138 public function makeConfig( $name ) {
139 if ( !isset( $this->configs[$name] ) ) {
141 if ( !isset( $this->factoryFunctions[$key] ) ) {
144 if ( !isset( $this->factoryFunctions[$key] ) ) {
145 throw new ConfigException( "No registered builder available for $name." );
148 if ( $this->factoryFunctions[$key] instanceof Config ) {
149 $conf = $this->factoryFunctions[$key];
151 $conf = call_user_func( $this->factoryFunctions[$key], $this );
154 if ( $conf instanceof Config ) {
155 $this->configs[$name] = $conf;
157 throw new UnexpectedValueException( "The builder for $name returned a non-Config object." );
161 return $this->configs[$name];
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.