This is a modified rebase of a patch by Tim, see I75f405930a7b14561389c59d147640e870146bec. Some benchmark results (from my laptop): Loading defaults from config-schema.php: - Master: 115/sec ( 8.7ms) - I75f4059: (Tim): 575/sec ( 1.7ms) - Id9dd0bf: (Daniel): 1120/sec ( 0.9ms) - This (Tim+Daniel): 1420/sec ( 0.7ms) Loading defaults and merging settings (worst case): - Master: 80/sec (12.4ms) - I75f4059: (Tim): 93/sec (10.8ms) - Id9dd0bf: (Daniel): 200/sec ( 4.9ms) - This (Tim+Daniel): 682/sec ( 1.5ms) Original commit message by Tim: * Explicitly import function array_key_exists to activate the special opcode * Batch creation of MergeStrategy objects * Batch default assignment to ArrayConfigBuilder The batches mostly help by allowing more inlining, eliminating some function calls. Reduced time for apply/finalize benchmark from 540µs to 170µs. Co-Authored-By: Tim Starling <tstarling@wikimedia.org> Change-Id: I3d4dd685eaaa4351801b3bac6ce1592eea925c5f
65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Settings\Config;
|
|
|
|
use Config;
|
|
use MediaWiki\Settings\SettingsBuilderException;
|
|
|
|
/**
|
|
* Builder for Config objects.
|
|
*
|
|
* @unstable
|
|
*/
|
|
interface ConfigBuilder {
|
|
|
|
/**
|
|
* Set the configuration $key to $value.
|
|
*
|
|
* @param string $key
|
|
* @param mixed $value
|
|
* @param MergeStrategy|null $mergeStrategy strategy for merging array config values.
|
|
* @return ConfigBuilder
|
|
*/
|
|
public function set( string $key, $value, MergeStrategy $mergeStrategy = null ): ConfigBuilder;
|
|
|
|
/**
|
|
* Set all values in the array.
|
|
*
|
|
* @param array $values
|
|
* @param MergeStrategy[] $mergeStrategies The merge strategies indexed by config key
|
|
* @return ConfigBuilder
|
|
*/
|
|
public function setMulti( array $values, array $mergeStrategies = [] ): ConfigBuilder;
|
|
|
|
/**
|
|
* Set the default for the configuration $key to $defaultValue.
|
|
*
|
|
* If the $key is already set, non-array $defaultValue will be ignored,
|
|
* for array $defaultValue the existing value will be merged into it as
|
|
* if the default was already there when the existing value was set.
|
|
*
|
|
* @param string $key
|
|
* @param mixed $defaultValue
|
|
* @param MergeStrategy|null $mergeStrategy strategy for merging array config values.
|
|
* @return ConfigBuilder
|
|
*/
|
|
public function setDefault( string $key, $defaultValue, MergeStrategy $mergeStrategy = null ): ConfigBuilder;
|
|
|
|
/**
|
|
* Set defaults in a batch.
|
|
*
|
|
* @param array $defaults The default values
|
|
* @param MergeStrategy[] $mergeStrategies The merge strategies indexed by config key
|
|
* @return ConfigBuilder
|
|
* @throws SettingsBuilderException if a merge strategy is not provided and
|
|
* the value is not an array.
|
|
*/
|
|
public function setMultiDefault( array $defaults, array $mergeStrategies ): ConfigBuilder;
|
|
|
|
/**
|
|
* Build the resulting Config object.
|
|
*
|
|
* @return Config
|
|
*/
|
|
public function build(): Config;
|
|
}
|