MediaWiki REL1_39
MediaWiki\Settings\SettingsBuilder Class Reference

Utility for loading settings files. More...

Public Member Functions

 __construct (string $baseDir, ExtensionRegistry $extensionRegistry, ConfigBuilder $configSink, PhpIniSink $phpIniSink, BagOStuff $cache=null)
 
 apply ()
 Apply any settings loaded so far to the runtime environment.
 
 assumeDirtyConfig ()
 Notify SettingsBuilder that it can no longer assume that is has full knowledge of all configuration variables that have been set.
 
 detectDeprecatedConfig ()
 Detect usage of deprecated settings.
 
 fileExists (string $path)
 Checks whether the given file exists relative to the settings builder's base directory.
 
 finalize ()
 Settings can't be loaded and applied after calling this method.
 
 getConfig ()
 Returns the config loaded so far.
 
 getConfigBuilder ()
 
 getConfigSchema ()
 Return the configuration schema.
 
 getDefaultConfig ()
 Return a Config object with default for all settings from all schemas loaded so far.
 
 getDefinedConfigKeys ()
 Returns the names of all defined configuration variables.
 
 getWarnings ()
 Returns any warnings logged by calling warning().
 
 load (SettingsSource $source)
 Load settings from a SettingsSource.
 
 loadArray (array $newSettings)
 Load settings from an array.
 
 loadFile (string $path)
 Load settings from a file.
 
 overrideConfigValue (string $key, $value)
 Override the value of a config variable.
 
 overrideConfigValues (array $values)
 Override the value of multiple config variables.
 
 putConfigValue (string $key, $value)
 Puts a value into a config variable.
 
 putConfigValues (array $values)
 Sets the value of multiple config variables.
 
 validate ()
 Assert that the config loaded so far conforms the schema loaded so far.
 
 warning (string $msg)
 Log a settings related warning, such as a deprecated config variable.
 

Detailed Description

Utility for loading settings files.

Since
1.38

Definition at line 29 of file SettingsBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Settings\SettingsBuilder::__construct ( string $baseDir,
ExtensionRegistry $extensionRegistry,
ConfigBuilder $configSink,
PhpIniSink $phpIniSink,
BagOStuff $cache = null )
Parameters
string$baseDir
ExtensionRegistry$extensionRegistry
ConfigBuilder$configSink
PhpIniSink$phpIniSink
BagOStuff | null$cacheBagOStuff used to cache settings loaded from each source. The caller should beware that secrets contained in any source passed to load or loadFile will be cached as well.

Definition at line 96 of file SettingsBuilder.php.

References $cache, MediaWiki\MainConfigNames\ExtensionDirectory, and MediaWiki\MainConfigNames\StyleDirectory.

Member Function Documentation

◆ apply()

MediaWiki\Settings\SettingsBuilder::apply ( )

Apply any settings loaded so far to the runtime environment.

Note
This usually makes all configuration available in global variables. This may however not be the case in the future.
Returns
$this
Exceptions
SettingsBuilderException

Definition at line 279 of file SettingsBuilder.php.

◆ assumeDirtyConfig()

MediaWiki\Settings\SettingsBuilder::assumeDirtyConfig ( )

Notify SettingsBuilder that it can no longer assume that is has full knowledge of all configuration variables that have been set.

This would be the case when other code (such as LocalSettings.php) is manipulating global variables which represent config values.

This is used for optimization: up until this method is called, default values can be set directly for any config values that have not been set yet. This avoids the need to run merge logic for all default values during initialization.

Note
It is useful to call apply() just before this method, so any settings already queued will still benefit from assuming that globals are not dirty.
Returns
self

Definition at line 376 of file SettingsBuilder.php.

◆ detectDeprecatedConfig()

MediaWiki\Settings\SettingsBuilder::detectDeprecatedConfig ( )

Detect usage of deprecated settings.

A setting is counted as used if it has a value other than the default.

Note
this is slow, so you probably don't want to do this on every request.
Returns
array<string,string> an associative array mapping config keys to the deprecation messages from the schema.

Definition at line 210 of file SettingsBuilder.php.

◆ fileExists()

MediaWiki\Settings\SettingsBuilder::fileExists ( string $path)

Checks whether the given file exists relative to the settings builder's base directory.

Parameters
string$path
Returns
bool

Definition at line 159 of file SettingsBuilder.php.

◆ finalize()

MediaWiki\Settings\SettingsBuilder::finalize ( )

Settings can't be loaded and applied after calling this method.

Access: internal
Most likely called only in Setup.php.
Returns
void

Definition at line 602 of file SettingsBuilder.php.

◆ getConfig()

MediaWiki\Settings\SettingsBuilder::getConfig ( )

Returns the config loaded so far.

Implicitly triggers apply() when needed.

Note
This will implicitly call apply()
Returns
Config

Definition at line 571 of file SettingsBuilder.php.

Referenced by MediaWiki\Maintenance\MaintenanceRunner\overrideConfig().

◆ getConfigBuilder()

MediaWiki\Settings\SettingsBuilder::getConfigBuilder ( )
Access: internal
For use in Setup.php, pending a better solution.
Returns
ConfigBuilder

Definition at line 611 of file SettingsBuilder.php.

◆ getConfigSchema()

MediaWiki\Settings\SettingsBuilder::getConfigSchema ( )

Return the configuration schema.

Note
This will implicitly call apply()
Returns
ConfigSchema

Definition at line 255 of file SettingsBuilder.php.

◆ getDefaultConfig()

MediaWiki\Settings\SettingsBuilder::getDefaultConfig ( )

Return a Config object with default for all settings from all schemas loaded so far.

If the schema for a setting doesn't specify a default, null is assumed.

Note
This will implicitly call apply()
Returns
IterableConfig

Definition at line 240 of file SettingsBuilder.php.

◆ getDefinedConfigKeys()

MediaWiki\Settings\SettingsBuilder::getDefinedConfigKeys ( )

Returns the names of all defined configuration variables.

Returns
string[]

Definition at line 265 of file SettingsBuilder.php.

◆ getWarnings()

MediaWiki\Settings\SettingsBuilder::getWarnings ( )

Returns any warnings logged by calling warning().

Access: internal
Returns
string[]

Definition at line 638 of file SettingsBuilder.php.

◆ load()

MediaWiki\Settings\SettingsBuilder::load ( SettingsSource $source)

Load settings from a SettingsSource.

Parameters
SettingsSource$source
Returns
$this

Definition at line 122 of file SettingsBuilder.php.

◆ loadArray()

MediaWiki\Settings\SettingsBuilder::loadArray ( array $newSettings)

Load settings from an array.

Parameters
array$newSettings
Returns
$this

Definition at line 138 of file SettingsBuilder.php.

◆ loadFile()

MediaWiki\Settings\SettingsBuilder::loadFile ( string $path)

Load settings from a file.

Parameters
string$path
Returns
$this

Definition at line 148 of file SettingsBuilder.php.

◆ overrideConfigValue()

MediaWiki\Settings\SettingsBuilder::overrideConfigValue ( string $key,
$value )

Override the value of a config variable.

This ignores any merge strategies and discards any previous value. This is a shorthand for overrideConfigValues( [ $key => $value ] ).

See also
putConfigValue
Parameters
string$keythe name of the config setting
mixed$valueThe value to set
Returns
$this

Definition at line 545 of file SettingsBuilder.php.

◆ overrideConfigValues()

MediaWiki\Settings\SettingsBuilder::overrideConfigValues ( array $values)

Override the value of multiple config variables.

This ignores any merge strategies and discards any previous value. This is a shorthand for loadArray( [ 'config-overrides' => $values ] ).

See also
putConfigValues
Parameters
array$valuesAn associative array mapping names to values.
Returns
$this

Definition at line 560 of file SettingsBuilder.php.

Referenced by Installer\overrideConfig().

◆ putConfigValue()

MediaWiki\Settings\SettingsBuilder::putConfigValue ( string $key,
$value )

Puts a value into a config variable.

Depending on the variable's specification, the new value may be merged with the previous value, or may replace it. This is a shorthand for putConfigValues( [ $key => $value ] ).

See also
overrideConfigValue
Parameters
string$keythe name of the config setting
mixed$valueThe value to set
Returns
$this

Definition at line 513 of file SettingsBuilder.php.

Referenced by MediaWiki\Maintenance\MaintenanceRunner\overrideConfig().

◆ putConfigValues()

MediaWiki\Settings\SettingsBuilder::putConfigValues ( array $values)

Sets the value of multiple config variables.

Depending on the variables' specification, the new values may be merged with the previous values, or they may replace them. This is a shorthand for loadArray( [ 'config' => $values ] ).

See also
overrideConfigValues
Parameters
array$valuesAn associative array mapping names to values.
Returns
$this

Definition at line 529 of file SettingsBuilder.php.

◆ validate()

MediaWiki\Settings\SettingsBuilder::validate ( )

Assert that the config loaded so far conforms the schema loaded so far.

Note
this is slow, so you probably don't want to do this on every request.
Returns
StatusValue

Definition at line 196 of file SettingsBuilder.php.

◆ warning()

MediaWiki\Settings\SettingsBuilder::warning ( string $msg)

Log a settings related warning, such as a deprecated config variable.

This can be used during bootstrapping, when the regular logger is not yet available. The warnings will be passed to a regular logger after bootstrapping is complete. In addition, the updater will fail if it finds any warnings. This allows us to warn about deprecated settings, and make sure they are replaced before the update proceeds.

Parameters
string$msg

Definition at line 627 of file SettingsBuilder.php.


The documentation for this class was generated from the following file: