2020-11-22 20:00:48 +00:00
|
|
|
<?php
|
2021-10-01 22:52:30 +00:00
|
|
|
|
2020-11-22 20:00:48 +00:00
|
|
|
namespace DPL;
|
|
|
|
|
2021-10-01 22:52:30 +00:00
|
|
|
use MWException;
|
|
|
|
|
2020-11-22 20:00:48 +00:00
|
|
|
class Config {
|
|
|
|
/**
|
|
|
|
* Configuration Settings
|
|
|
|
*
|
2021-02-22 23:48:01 +00:00
|
|
|
* @var array
|
2020-11-22 20:00:48 +00:00
|
|
|
*/
|
2021-02-22 23:48:01 +00:00
|
|
|
private static $settings = [];
|
2020-11-22 20:00:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the static object with settings.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @param array|false $settings
|
2020-11-22 20:00:48 +00:00
|
|
|
*/
|
2021-02-22 23:48:01 +00:00
|
|
|
public static function init( $settings = false ) {
|
|
|
|
if ( $settings === false ) {
|
2020-11-22 20:00:48 +00:00
|
|
|
global $wgDplSettings;
|
|
|
|
|
2021-10-01 22:52:30 +00:00
|
|
|
$settings = $wgDplSettings ?? false;
|
2020-11-22 20:00:48 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 23:48:01 +00:00
|
|
|
if ( !is_array( $settings ) ) {
|
|
|
|
throw new MWException( __METHOD__ . ": Invalid settings passed." );
|
2020-11-22 20:00:48 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 23:48:01 +00:00
|
|
|
self::$settings = array_merge( self::$settings, $settings );
|
2020-11-22 20:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a single setting.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @param string $setting
|
|
|
|
* @return mixed|null
|
2020-11-22 20:00:48 +00:00
|
|
|
*/
|
2021-02-22 23:48:01 +00:00
|
|
|
public static function getSetting( $setting ) {
|
2021-10-01 22:52:30 +00:00
|
|
|
return ( self::$settings[$setting] ?? null );
|
2020-11-22 20:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a all settings.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @return array
|
2020-11-22 20:00:48 +00:00
|
|
|
*/
|
|
|
|
public static function getAllSettings() {
|
|
|
|
return self::$settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a single setting.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @param string $setting
|
|
|
|
* @param mixed|null $value
|
2020-11-22 20:00:48 +00:00
|
|
|
*/
|
2021-02-22 23:48:01 +00:00
|
|
|
public static function setSetting( $setting, $value = null ) {
|
|
|
|
if ( empty( $setting ) || !is_string( $setting ) ) {
|
|
|
|
throw new MWException( __METHOD__ . ": Setting keys can not be blank." );
|
2020-11-22 20:00:48 +00:00
|
|
|
}
|
2021-10-01 22:52:30 +00:00
|
|
|
|
2020-11-22 20:00:48 +00:00
|
|
|
self::$settings[$setting] = $value;
|
|
|
|
}
|
|
|
|
}
|