added test support
This commit is contained in:
parent
c166b5774c
commit
010914b7bd
|
@ -9,7 +9,21 @@ class ConfigController
|
|||
{
|
||||
private array $config;
|
||||
|
||||
public function __construct(bool $verbose = false, bool $quiet = false) {
|
||||
/**
|
||||
* @param bool $verbose
|
||||
* @param bool $quiet
|
||||
* @param bool $test
|
||||
*/
|
||||
public function __construct(bool $verbose = false, bool $quiet = false, bool $test = false)
|
||||
{
|
||||
|
||||
if ($test) {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.test";
|
||||
if (!file_exists(filename: $configFile)) {
|
||||
echo 'No testing (config.json.test) config has benn setup.' . PHP_EOL;
|
||||
die(1);
|
||||
}
|
||||
} else {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local";
|
||||
if (!file_exists(filename: $configFile)) {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
|
||||
|
@ -26,6 +40,7 @@ class ConfigController
|
|||
}
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
$configJSON = file_get_contents(filename: $configFile);
|
||||
|
||||
if (json_decode(json: $configJSON) === null) {
|
||||
|
@ -36,19 +51,13 @@ class ConfigController
|
|||
|
||||
$this->config = json_decode(json: $configJSON, associative: true);
|
||||
|
||||
if ($verbose) {
|
||||
$this->config['verbose'] = true;
|
||||
} else {
|
||||
$this->config['verbose'] = false;
|
||||
}
|
||||
if ($quiet) {
|
||||
$this->config['quiet'] = true;
|
||||
} else {
|
||||
$this->config['quiet'] = false;
|
||||
}
|
||||
$this->config['verbose'] = (bool)$verbose;
|
||||
$this->config['quiet'] = (bool)$quiet;
|
||||
$this->config['test'] = (bool)$test;
|
||||
}
|
||||
|
||||
public function getConfig(string $configKey): string {
|
||||
public function getConfig(string $configKey): string
|
||||
{
|
||||
return $this->config[$configKey];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue