<?php
function loadEnv($filePath) {
    if (!file_exists($filePath)) {
        return false;
    }

    $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    if ($lines === false) {
        return false;
    }

    foreach ($lines as $line) {
        // Skip comments
        if (strpos(trim($line), '#') === 0) {
            continue;
        }

        list($key, $value) = explode('=', $line, 2);
        $_ENV[trim($key)] = trim($value);
    }

    return true;
}

// Load the .env file
loadEnv(__DIR__ . '/.env');

const DB_HOST = isset($_ENV['DB_HOST']) ? $_ENV['DB_HOST'] : 'localhost';
const DB_DATABASE = isset($_ENV['DB_DATABASE']) ? $_ENV['DB_DATABASE'] : 'heartTrack';
const DB_USER = isset($_ENV['DB_USER']) ? $_ENV['DB_USER'] : 'toto';
const DB_PASSWORD = isset($_ENV['DB_PASSWORD']) ? $_ENV['DB_PASSWORD'] : 'achanger';
const APP_ENV = isset($_ENV['APP_ENV']) ? $_ENV['APP_ENV'] : 'development';

const dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_DATABASE;
