The goal is to keep the actual default values for settings in the same place as the setting is declared, and applied using the regular means for loading the settings -- not in a separate piece of code that needs to be loaded through some entirely different mechanism. SetupDynamicConfig.php now contains a few categories of things: * Post-processing of configuration settings, where already-set settings are altered. This could be moved to MainConfigSchema too as a separate set of methods. * Processing of old aliases of settings (blacklist, slave) that are not registered as settings anymore and therefore are not available to MainConfigSchema. This could perhaps be moved to LocalSettings processing somehow? * Setting $wgUseEnotif, which is also not registered as a setting. Easiest would be just to declare it as a setting and have it set unconditionally. * Setting the actual timezone to $wgLocaltimezone. This is not related to configuration and should just be in Setup.php. Bug: T305093 Change-Id: Ia5c23b52dbbfcb3d07ffcf5d3b7f2d7befba2a26
72 lines
1.6 KiB
PHP
72 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Settings\Config;
|
|
|
|
abstract class ConfigBuilderBase implements ConfigBuilder {
|
|
|
|
abstract protected function has( string $key ): bool;
|
|
|
|
abstract protected function update( string $key, $value );
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function set(
|
|
string $key,
|
|
$newValue,
|
|
MergeStrategy $mergeStrategy = null
|
|
): ConfigBuilder {
|
|
if ( $mergeStrategy && $this->has( $key ) && is_array( $newValue ) ) {
|
|
$oldValue = $this->get( $key );
|
|
if ( $oldValue && is_array( $oldValue ) ) {
|
|
$newValue = $mergeStrategy->merge( $oldValue, $newValue );
|
|
}
|
|
}
|
|
$this->update( $key, $newValue );
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function setMulti( array $values, array $mergeStrategies = [] ): ConfigBuilder {
|
|
foreach ( $values as $key => $value ) {
|
|
$this->set( $key, $value, $mergeStrategies[$key] ?? null );
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function setDefault(
|
|
string $key,
|
|
$defaultValue,
|
|
MergeStrategy $mergeStrategy = null
|
|
): ConfigBuilder {
|
|
if ( $this->has( $key ) ) {
|
|
if ( $mergeStrategy && $defaultValue && is_array( $defaultValue ) ) {
|
|
$customValue = $this->get( $key );
|
|
if ( is_array( $customValue ) ) {
|
|
$newValue = $mergeStrategy->merge( $defaultValue, $customValue );
|
|
$this->update( $key, $newValue );
|
|
}
|
|
}
|
|
} else {
|
|
$this->update( $key, $defaultValue );
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function setMultiDefault( array $defaults, array $mergeStrategies ): ConfigBuilder {
|
|
foreach ( $defaults as $key => $defaultValue ) {
|
|
$this->setDefault( $key, $defaultValue, $mergeStrategies[$key] ?? null );
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
}
|