<?php

declare(strict_types=1);

/**
 * PSR-4 style autoloader.
 *
 * Namespaces:
 *   Core\       → /core/
 *   App\        → /app/
 */
spl_autoload_register(function (string $class): void {
    $namespaceMap = [
        'Core\\'  => BASE_PATH . '/core/',
        'App\\'   => BASE_PATH . '/app/',
    ];

    foreach ($namespaceMap as $prefix => $baseDir) {
        if (!str_starts_with($class, $prefix)) {
            continue;
        }

        $relative = substr($class, strlen($prefix));
        $file     = $baseDir . str_replace('\\', '/', $relative) . '.php';

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