<?php

declare(strict_types=1);

/**
 * Amorçage commun (web + CLI) : autoloader, configuration, helpers.
 * Ne démarre PAS la session (réservé au contexte web).
 */

if (!defined('BASE_PATH')) {
    define('BASE_PATH', dirname(__DIR__));
}

spl_autoload_register(static function (string $class): void {
    $prefix = 'App\\';
    if (!str_starts_with($class, $prefix)) {
        return;
    }
    $relative = substr($class, strlen($prefix));
    $file     = BASE_PATH . '/src/' . str_replace('\\', '/', $relative) . '.php';
    if (is_file($file)) {
        require $file;
    }
});

\App\Core\Config::load(require BASE_PATH . '/config/config.php');

require BASE_PATH . '/src/Support/helpers.php';
