initial commit

This commit is contained in:
tracer 2022-10-21 14:48:56 +02:00
parent fdd24d90da
commit 9b3a6b1f3a
1 changed files with 40 additions and 0 deletions

40
src/Service/Config.php Normal file
View File

@ -0,0 +1,40 @@
<?php
namespace App\Service;
use Exception;
/**
*
*/
class Config
{
private array $config;
/**
* @throws Exception
*/
public function __construct()
{
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local";
if (!file_exists(filename: $configFile)) {
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
}
if (!file_exists(filename: $configFile)) {
throw new Exception(message: 'Missing config file');
}
$configJSON = file_get_contents(filename: $configFile);
if (json_decode(json: $configJSON) === null) {
throw new Exception(message: 'Config file is not valid JSON.');
}
$this->config = json_decode(json: $configJSON, associative: true);
}
public function getConfig(string $configKey): string
{
return $this->config[$configKey];
}
}