<?php

/**
 * ITSWEBER CMS – PSR-4 compatible Autoloader
 *
 * Maps the App namespace to the app/ directory.
 */
class Autoloader
{
    private static string $basePath = '';

    public static function register(string $basePath): void
    {
        self::$basePath = rtrim($basePath, '/');
        spl_autoload_register([self::class, 'load']);
    }

    public static function load(string $className): void
    {
        // Only handle App\ namespace
        if (strpos($className, 'App\\') !== 0) {
            return;
        }

        // Convert namespace to file path
        $relativePath = str_replace('\\', '/', substr($className, 4));
        $file = self::$basePath . '/app/' . $relativePath . '.php';

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