parent
ad784311c1
commit
0acb2c038c
@ -1,97 +1,152 @@ |
|||||||
<?php |
<?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 |
||||||
|
*/ |
||||||
|
|
||||||
final class configure { |
/** |
||||||
private static $config = array(); |
* Configure your app |
||||||
protected function __construct() { } |
* |
||||||
|
* @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 |
||||||
|
{ |
||||||
|
|
||||||
|
/** |
||||||
|
* 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 |
* Fetches a setting set from using Configure::set() or add or update |
||||||
* |
* |
||||||
* $name The name of the setting to get |
* @param string $name The name of the setting to get |
||||||
* $key [optional] The Array Key to fetch |
* @param string|false $key [optional] The Array Key to fetch |
||||||
* The setting specified by $name, or null if $name was not set |
* 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)])) { |
public static function get(string $name, string|false $key = false): mixed |
||||||
$a = self::$config[strtolower($name)]; |
{ |
||||||
if ($key === false) { |
if (isset(static::$_config[strtolower($name)])) { |
||||||
return $a; |
$a = static::$_config[strtolower($name)]; |
||||||
} |
if ($key === false) { |
||||||
if (isset($a[$key])) { |
return $a; |
||||||
return $a[$key]; |
} |
||||||
} |
if (isset($a[$key])) { |
||||||
|
return $a[$key]; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
} |
} |
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
/* |
/** |
||||||
* Checks if the setting exists |
* Checks if the setting exists |
||||||
* |
* |
||||||
* $name The name of the setting to check existance |
* @param $name The name of the setting to check existance |
||||||
* return boolean true if $name was set, false otherwise |
* |
||||||
*/ |
* @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 |
||||||
return true; |
{ |
||||||
|
if (array_key_exists(strtolower($name), static::$_config)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
} |
} |
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
/* |
/** |
||||||
* Overwrite/Update/Add to $config |
* Overwrite/Update/Add to $config |
||||||
* $name the main key to update |
* |
||||||
* $key the sub key |
* @param string $name the main key to update. |
||||||
* type $value the data to update |
* @param string $key the sub key. |
||||||
*/ |
* @param mixed $value the data to update |
||||||
public static function update(string $name, string $key, $value): void { |
* |
||||||
self::$config[strtolower($name)][strtolower($key)] = $value; |
* @return void not ah |
||||||
} |
*/ |
||||||
|
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 |
* Add to existing data without loss... to $config |
||||||
* $name the main key |
* |
||||||
* $key the sub key |
* @param string $name the main key |
||||||
* $value new data to add |
* @param string $key the sub key |
||||||
*/ |
* @param mixed $value new data to add |
||||||
public static function add(string $name, string $key, $value): void { |
* |
||||||
self::$config[strtolower($name)][strtolower($key)][] = $value; |
* @return void not ah |
||||||
} |
*/ |
||||||
|
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 |
* 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 |
||||||
*/ |
* |
||||||
public static function free(string $name): void { |
* @return void not ah |
||||||
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 |
* Adds the given $value to the configuration using the $name given |
||||||
* |
* |
||||||
* $name The name to give this setting. Use Configure::exists() |
* @param string $name The name to give this setting. Use Configure::exists() |
||||||
* to check for pre-existing settings with the same name |
* to check for pre-existing settings with the same name. |
||||||
* $value The value to set |
* @param mixed $value The value to set |
||||||
*/ |
* |
||||||
public static function set(string $name, $value): void { |
* @return void not ah |
||||||
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 |
* Sets $config data from an Array |
||||||
* array $a ($name => $value) |
* |
||||||
* retutns a void |
* @param array $a ($name => $value) |
||||||
*/ |
* |
||||||
public static function load_array(array $a): void { |
* @return void not ah |
||||||
foreach ($a as $name => $value) { |
*/ |
||||||
self::$config[strtolower($name)] = $value; |
public static function loadArray(array $a): void |
||||||
|
{ |
||||||
|
foreach ($a as $name => $value) { |
||||||
|
static::$_config[strtolower($name)] = $value; |
||||||
|
} |
||||||
|
unset($a); |
||||||
} |
} |
||||||
unset($a); |
|
||||||
} |
|
||||||
|
|
||||||
} // end of configure |
} // end of configure |
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,7 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
$ok = useMe('wget'); |
||||||
|
if ($ok !== false) { |
||||||
|
doCommand('wget::download', 'phpcs', 'https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar'); |
||||||
|
doCommand('wget::download', 'phpcbf', 'https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar'); |
||||||
|
} |
||||||
Loading…
Reference in new issue