|
|
|
|
@ -1,21 +1,56 @@ |
|
|
|
|
<?php |
|
|
|
|
/** |
|
|
|
|
* Setup Config data |
|
|
|
|
* |
|
|
|
|
* PHP version 8.3 |
|
|
|
|
* |
|
|
|
|
* @category Util |
|
|
|
|
* @package Neato |
|
|
|
|
* @author Robert S. <tips@technowizardbob.com> |
|
|
|
|
* @license https://mit-license.org/ MIT License |
|
|
|
|
* @link https://git.mysnippetsofcode.com/tts/neatoDeploy |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Configure your app |
|
|
|
|
* |
|
|
|
|
* @category Util |
|
|
|
|
* @package Neato |
|
|
|
|
* @author Robert S. <tips@technowizardbob.com> |
|
|
|
|
* @license https://mit-license.org/ MIT License |
|
|
|
|
* @link https://git.mysnippetsofcode.com/tts/neatoDeploy |
|
|
|
|
*/ |
|
|
|
|
final class Configure |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
final class configure { |
|
|
|
|
private static $config = array(); |
|
|
|
|
protected function __construct() { } |
|
|
|
|
/** |
|
|
|
|
* This private static var holds all configuration data. |
|
|
|
|
* |
|
|
|
|
* @staticvar static array $config holds all system config data. |
|
|
|
|
*/ |
|
|
|
|
private static array $_config = []; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Deny creating instance as all methods are static here. |
|
|
|
|
*/ |
|
|
|
|
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 |
|
|
|
|
* @param string $name The name of the setting to get |
|
|
|
|
* @param string|false $key [optional] The Array Key to fetch |
|
|
|
|
* The setting specified by $name, |
|
|
|
|
* or null if $name was not set |
|
|
|
|
* |
|
|
|
|
* return type: ?array |
|
|
|
|
* @return mixed Fetch Config data |
|
|
|
|
*/ |
|
|
|
|
public static function get(string $name, $key = false) { |
|
|
|
|
if (isset(self::$config[strtolower($name)])) { |
|
|
|
|
$a = self::$config[strtolower($name)]; |
|
|
|
|
public static function get(string $name, string|false $key = false): mixed |
|
|
|
|
{ |
|
|
|
|
if (isset(static::$_config[strtolower($name)])) { |
|
|
|
|
$a = static::$_config[strtolower($name)]; |
|
|
|
|
if ($key === false) { |
|
|
|
|
return $a; |
|
|
|
|
} |
|
|
|
|
@ -26,69 +61,89 @@ final class configure { |
|
|
|
|
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 |
|
|
|
|
* @param $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)) { |
|
|
|
|
public static function exists(string $name): bool |
|
|
|
|
{ |
|
|
|
|
if (array_key_exists(strtolower($name), static::$_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 |
|
|
|
|
* |
|
|
|
|
* @param string $name the main key to update. |
|
|
|
|
* @param string $key the sub key. |
|
|
|
|
* @param mixed $value the data to update |
|
|
|
|
* |
|
|
|
|
* @return void not ah |
|
|
|
|
*/ |
|
|
|
|
public static function update(string $name, string $key, $value): void { |
|
|
|
|
self::$config[strtolower($name)][strtolower($key)] = $value; |
|
|
|
|
public static function update(string $name, string $key, mixed $value): void |
|
|
|
|
{ |
|
|
|
|
static::$_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 |
|
|
|
|
* |
|
|
|
|
* @param string $name the main key |
|
|
|
|
* @param string $key the sub key |
|
|
|
|
* @param mixed $value new data to add |
|
|
|
|
* |
|
|
|
|
* @return void not ah |
|
|
|
|
*/ |
|
|
|
|
public static function add(string $name, string $key, $value): void { |
|
|
|
|
self::$config[strtolower($name)][strtolower($key)][] = $value; |
|
|
|
|
public static function add(string $name, string $key, mixed $value): void |
|
|
|
|
{ |
|
|
|
|
static::$_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 |
|
|
|
|
* use should be freed using this method whenever possible. |
|
|
|
|
* |
|
|
|
|
* $name The name of the setting to free |
|
|
|
|
* @param string $name The name of the setting to free |
|
|
|
|
* |
|
|
|
|
* @return void not ah |
|
|
|
|
*/ |
|
|
|
|
public static function free(string $name): void { |
|
|
|
|
if (self::exists($name)) |
|
|
|
|
unset(self::$config[strtolower($name)]); |
|
|
|
|
public static function free(string $name): void |
|
|
|
|
{ |
|
|
|
|
if (static::exists($name)) { |
|
|
|
|
unset(static::$_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 |
|
|
|
|
* @param string $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 |
|
|
|
|
* |
|
|
|
|
* @return void not ah |
|
|
|
|
*/ |
|
|
|
|
public static function set(string $name, $value): void { |
|
|
|
|
self::$config[strtolower($name)] = $value; |
|
|
|
|
public static function set(string $name, mixed $value): void |
|
|
|
|
{ |
|
|
|
|
static::$_config[strtolower($name)] = $value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/** |
|
|
|
|
* Sets $config data from an Array |
|
|
|
|
* array $a ($name => $value) |
|
|
|
|
* retutns a void |
|
|
|
|
* |
|
|
|
|
* @param array $a ($name => $value) |
|
|
|
|
* |
|
|
|
|
* @return void not ah |
|
|
|
|
*/ |
|
|
|
|
public static function load_array(array $a): void { |
|
|
|
|
public static function loadArray(array $a): void |
|
|
|
|
{ |
|
|
|
|
foreach ($a as $name => $value) { |
|
|
|
|
self::$config[strtolower($name)] = $value; |
|
|
|
|
static::$_config[strtolower($name)] = $value; |
|
|
|
|
} |
|
|
|
|
unset($a); |
|
|
|
|
} |
|
|
|
|
|