|
|
|
|
@ -4,12 +4,12 @@ final class configure { |
|
|
|
|
private static $config = array(); |
|
|
|
|
protected function __construct() { } |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/* |
|
|
|
|
* Fetches a setting set from using Configure::set() or add or update |
|
|
|
|
* |
|
|
|
|
* @param string $name The name of the setting to get |
|
|
|
|
* @param string $key [optional] The Array Key to fetch |
|
|
|
|
* @return mixed The setting specified by $name, or null if $name was not set |
|
|
|
|
* $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 |
|
|
|
|
*/ |
|
|
|
|
@ -26,11 +26,11 @@ final class configure { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/* |
|
|
|
|
* Checks if the setting exists |
|
|
|
|
* |
|
|
|
|
* @param string $name The name of the setting to check existance |
|
|
|
|
* @return boolean true if $name was set, false otherwise |
|
|
|
|
* $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)) { |
|
|
|
|
@ -39,58 +39,56 @@ final class configure { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/* |
|
|
|
|
* Overwrite/Update/Add to $config |
|
|
|
|
* @param string $name the main key to update |
|
|
|
|
* @param string $key the sub key |
|
|
|
|
* @param type $value the data to update |
|
|
|
|
* $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 |
|
|
|
|
* @param string $name the main key |
|
|
|
|
* @param string $key the sub key |
|
|
|
|
* @param type $value new data to add |
|
|
|
|
* $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 |
|
|
|
|
* |
|
|
|
|
* @param string $name The name of the setting to free |
|
|
|
|
* $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 |
|
|
|
|
* |
|
|
|
|
* @param string $name The name to give this setting. Use Configure::exists() |
|
|
|
|
* $name The name to give this setting. Use Configure::exists() |
|
|
|
|
* to check for pre-existing settings with the same name |
|
|
|
|
* @param mixed $value The value to set |
|
|
|
|
* $value The value to set |
|
|
|
|
*/ |
|
|
|
|
public static function set(string $name, $value): void { |
|
|
|
|
self::$config[strtolower($name)] = $value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/* |
|
|
|
|
* Sets $config data from an Array |
|
|
|
|
* @param array $a ($name => $value) |
|
|
|
|
* @retval void |
|
|
|
|
* array $a ($name => $value) |
|
|
|
|
* retutns a void |
|
|
|
|
*/ |
|
|
|
|
public static function load_array(array $a): void { |
|
|
|
|
if (isset($a) && is_array($a)) { |
|
|
|
|
foreach ($a as $name => $value) { |
|
|
|
|
self::$config[strtolower($name)] = $value; |
|
|
|
|
} |
|
|
|
|
foreach ($a as $name => $value) { |
|
|
|
|
self::$config[strtolower($name)] = $value; |
|
|
|
|
} |
|
|
|
|
unset($a); |
|
|
|
|
} |
|
|
|
|
|