You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.5 KiB
97 lines
2.5 KiB
<?php
|
|
|
|
final class configure {
|
|
private static $config = array();
|
|
protected function __construct() { }
|
|
|
|
/*
|
|
* Fetches a setting set from using Configure::set() or add or update
|
|
*
|
|
* $name The name of the setting to get
|
|
* $key [optional] The Array Key to fetch
|
|
* The setting specified by $name, or null if $name was not set
|
|
*
|
|
* return type: ?array
|
|
*/
|
|
public static function get(string $name, $key = false) {
|
|
if (isset(self::$config[strtolower($name)])) {
|
|
$a = self::$config[strtolower($name)];
|
|
if ($key === false) {
|
|
return $a;
|
|
}
|
|
if (isset($a[$key])) {
|
|
return $a[$key];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/*
|
|
* Checks if the setting exists
|
|
*
|
|
* $name The name of the setting to check existance
|
|
* return boolean true if $name was set, false otherwise
|
|
*/
|
|
public static function exists(string $name): bool {
|
|
if (array_key_exists(strtolower($name), self::$config)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* Overwrite/Update/Add to $config
|
|
* $name the main key to update
|
|
* $key the sub key
|
|
* type $value the data to update
|
|
*/
|
|
public static function update(string $name, string $key, $value): void {
|
|
self::$config[strtolower($name)][strtolower($key)] = $value;
|
|
}
|
|
|
|
/*
|
|
* Add to existing data without loss... to $config
|
|
* $name the main key
|
|
* $key the sub key
|
|
* $value new data to add
|
|
*/
|
|
public static function add(string $name, string $key, $value): void {
|
|
self::$config[strtolower($name)][strtolower($key)][] = $value;
|
|
}
|
|
|
|
/*
|
|
* Frees the setting given by $name, if it exists. All settings no longer in
|
|
* use should be freed using this method whenever possible
|
|
*
|
|
* $name The name of the setting to free
|
|
*/
|
|
public static function free(string $name): void {
|
|
if (self::exists($name))
|
|
unset(self::$config[strtolower($name)]);
|
|
}
|
|
|
|
/*
|
|
* Adds the given $value to the configuration using the $name given
|
|
*
|
|
* $name The name to give this setting. Use Configure::exists()
|
|
* to check for pre-existing settings with the same name
|
|
* $value The value to set
|
|
*/
|
|
public static function set(string $name, $value): void {
|
|
self::$config[strtolower($name)] = $value;
|
|
}
|
|
|
|
/*
|
|
* Sets $config data from an Array
|
|
* array $a ($name => $value)
|
|
* retutns a void
|
|
*/
|
|
public static function load_array(array $a): void {
|
|
foreach ($a as $name => $value) {
|
|
self::$config[strtolower($name)] = $value;
|
|
}
|
|
unset($a);
|
|
}
|
|
|
|
} // end of configure
|
|
|
|
|