2025-02-14 17:12:59 +01:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
class Config {
|
|
|
|
private static $config = null;
|
|
|
|
|
|
|
|
public static function load() {
|
|
|
|
if (self::$config === null) {
|
|
|
|
$configFile = __DIR__ . '/../config.json';
|
|
|
|
if (!file_exists($configFile)) {
|
|
|
|
throw new Exception('Configuration file not found');
|
|
|
|
}
|
|
|
|
self::$config = json_decode(file_get_contents($configFile), true);
|
|
|
|
}
|
|
|
|
return self::$config;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get($key, $default = null) {
|
|
|
|
$config = self::load();
|
|
|
|
return $config[$key] ?? $default;
|
|
|
|
}
|
2025-02-14 20:59:17 +01:00
|
|
|
|
|
|
|
public static function save($config) {
|
|
|
|
$configFile = __DIR__ . '/../config.json';
|
|
|
|
|
|
|
|
$jsonContent = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
|
|
|
|
|
|
if (file_put_contents($configFile, $jsonContent) === false) {
|
|
|
|
throw new Exception('Impossible de sauvegarder la configuration');
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$config = $config;
|
|
|
|
return true;
|
|
|
|
}
|
2025-02-14 17:12:59 +01:00
|
|
|
}
|