DynamicPageList3/includes/Config.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2020-11-22 20:00:48 +00:00
<?php
/**
* DynamicPageList3
* DPL Config Class
*
* @author IlyaHaykinson, Unendlich, Dangerville, Algorithmix, Theaitetos, Alexia E. Smith
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
2021-02-22 23:48:01 +00:00
*/
2020-11-22 20:00:48 +00:00
namespace DPL;
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.
*
* @access public
* @param array Settings to initialize for DPL.
* @return void
*/
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;
$settings = $wgDplSettings;
}
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.
*
* @access public
* @param string Setting Key
* @return mixed The setting's actual setting or null if it does not exist.
*/
2021-02-22 23:48:01 +00:00
public static function getSetting( $setting ) {
return ( array_key_exists( $setting, self::$settings ) ? self::$settings[$setting] : null );
2020-11-22 20:00:48 +00:00
}
/**
* Return a all settings.
*
* @access public
* @return array All settings
*/
public static function getAllSettings() {
return self::$settings;
}
/**
* Set a single setting.
*
* @access public
* @param string Setting Key
* @param mixed [Optional] Appropriate value for the setting key.
* @return void
*/
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
}
self::$settings[$setting] = $value;
}
}