Lectures/includes/config.php

22 lines
603 B
PHP

<?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;
}
}