This patch ensures that we know which arrays are lists (JsonSchema type "array") and which are maps (JsonSchema type "object"). We can then default to array_merge for lists and to array_plus for maps. This seems clearer than requiring an explicit merge strategy to be declared for all arrays. This patch specified a mergeTrategy for some config variables that need behavior different from the default. This patch also changes the merging behavior to allow non-array values to replace arrays and vice versa. It also changes the behavior of defaults to allow falsy values to override non-falsy defaults. Bug: T300129 Change-Id: Ia7b0c0250af6a957eac1efb554fb47511f5e093f
45 lines
915 B
PHP
45 lines
915 B
PHP
<?php
|
|
|
|
namespace MediaWiki\Settings\Config;
|
|
|
|
use Config;
|
|
use GlobalVarConfig;
|
|
|
|
class GlobalConfigBuilder extends ConfigBuilderBase {
|
|
|
|
/** @var string */
|
|
public const DEFAULT_PREFIX = 'wg';
|
|
|
|
/** @var string */
|
|
private $prefix;
|
|
|
|
/**
|
|
* @param string $prefix
|
|
*/
|
|
public function __construct( string $prefix = self::DEFAULT_PREFIX ) {
|
|
$this->prefix = $prefix;
|
|
}
|
|
|
|
protected function has( string $key ): bool {
|
|
$var = $this->getVarName( $key );
|
|
return array_key_exists( $var, $GLOBALS );
|
|
}
|
|
|
|
protected function get( string $key ) {
|
|
$var = $this->getVarName( $key );
|
|
return $GLOBALS[ $var ] ?? null;
|
|
}
|
|
|
|
protected function update( string $key, $value ) {
|
|
$var = $this->getVarName( $key );
|
|
$GLOBALS[ $var ] = $value;
|
|
}
|
|
|
|
private function getVarName( string $key ): string {
|
|
return $this->prefix . $key;
|
|
}
|
|
|
|
public function build(): Config {
|
|
return new GlobalVarConfig( $this->prefix );
|
|
}
|
|
}
|