<?php
// Standalone API Entry Point for CPanel deployment
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);

// Simple Autoloader for standalone structure
spl_autoload_register(function ($class) {
    $prefix = 'Api\\';
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return;
    }

    $relative_class = substr($class, $len);
    
    // Chemin exact (ex: Controllers/ApiController.php)
    $file = __DIR__ . '/' . str_replace('\\', '/', $relative_class) . '.php';
    
    // Si le dossier est en minuscules (ex: controllers/ApiController.php)
    if (!file_exists($file)) {
        $parts = explode('\\', $relative_class);
        if (count($parts) > 1) {
            $parts[0] = strtolower($parts[0]); // Met le nom du dossier en minuscules
            $file = __DIR__ . '/' . implode('/', $parts) . '.php';
        }
    }

    if (file_exists($file)) {
        require $file;
    }
});

use Api\Controllers\ApiController;

$controller = new ApiController();
$controller->handleRequest();
