GlobalConfigBuilder needs to use the appropriate merge strategy to combine new values with the value already rpesent in a global variable. For this, GlobalConfigBuilder needs to actually look at the current value of the global variable. Also, we need to define merge strategies for all settings that need them (at least the ones used directly by ExtensionProcessor). Change-Id: I834d4b3506bdd8d416e5eb6e03fb4dd6b60b6e05
38 lines
876 B
PHP
38 lines
876 B
PHP
<?php
|
|
|
|
namespace MediaWiki\Settings\Config;
|
|
|
|
use Config;
|
|
use HashConfig;
|
|
|
|
class ArrayConfigBuilder implements ConfigBuilder {
|
|
|
|
use ConfigBuilderTrait;
|
|
|
|
/** @var array */
|
|
protected $config = [];
|
|
|
|
public function set( string $key, $value, MergeStrategy $mergeStrategy = null ): ConfigBuilder {
|
|
$this->config[ $key ] =
|
|
$this->getNewValue( $key, $this->config[ $key ] ?? null, $value, $mergeStrategy );
|
|
return $this;
|
|
}
|
|
|
|
public function setDefault( string $key, $value, MergeStrategy $mergeStrategy = null ): ConfigBuilder {
|
|
if ( $mergeStrategy ) {
|
|
$this->set( $key, $value, $mergeStrategy->reverse() );
|
|
} elseif ( !array_key_exists( $key, $this->config ) ) {
|
|
$this->config[$key] = $value;
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Build the configuration.
|
|
*
|
|
* @return Config
|
|
*/
|
|
public function build(): Config {
|
|
return new HashConfig( $this->config );
|
|
}
|
|
}
|