<?php
namespace App\Core;

class Config
{
    private static ?array $data = null;

    public static function load(): void
    {
        if (self::$data === null) {
            self::$data = require __DIR__ . '/../../config/config.php';
        }
    }

    public static function get(string $dottedKey, $default = null)
    {
        self::load();
        $segments = explode('.', $dottedKey);
        $value = self::$data;
        foreach ($segments as $segment) {
            if (!is_array($value) || !array_key_exists($segment, $value)) {
                return $default;
            }
            $value = $value[$segment];
        }
        return $value;
    }
}
