2021-11-09 17:29:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Settings\Config;
|
|
|
|
|
|
|
|
|
|
use Config;
|
|
|
|
|
use HashConfig;
|
|
|
|
|
|
2021-11-16 20:41:38 +00:00
|
|
|
class ArrayConfigBuilder implements ConfigBuilder {
|
2021-11-09 17:29:14 +00:00
|
|
|
|
2022-01-21 20:07:42 +00:00
|
|
|
use ConfigBuilderTrait;
|
|
|
|
|
|
2021-11-09 17:29:14 +00:00
|
|
|
/** @var array */
|
2021-11-11 17:50:14 +00:00
|
|
|
protected $config = [];
|
|
|
|
|
|
2021-11-16 20:41:38 +00:00
|
|
|
public function set( string $key, $value, MergeStrategy $mergeStrategy = null ): ConfigBuilder {
|
2022-01-21 20:07:42 +00:00
|
|
|
$this->config[ $key ] =
|
|
|
|
|
$this->getNewValue( $key, $this->config[ $key ] ?? null, $value, $mergeStrategy );
|
2021-11-09 17:29:14 +00:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 20:41:38 +00:00
|
|
|
public function setDefault( string $key, $value, MergeStrategy $mergeStrategy = null ): ConfigBuilder {
|
2021-11-11 17:50:14 +00:00
|
|
|
if ( $mergeStrategy ) {
|
2022-01-21 20:07:42 +00:00
|
|
|
$this->set( $key, $value, $mergeStrategy->reverse() );
|
2021-11-11 17:50:14 +00:00
|
|
|
} elseif ( !array_key_exists( $key, $this->config ) ) {
|
|
|
|
|
$this->config[$key] = $value;
|
2021-11-09 17:29:14 +00:00
|
|
|
}
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the configuration.
|
|
|
|
|
*
|
|
|
|
|
* @return Config
|
|
|
|
|
*/
|
|
|
|
|
public function build(): Config {
|
|
|
|
|
return new HashConfig( $this->config );
|
|
|
|
|
}
|
|
|
|
|
}
|