<?php
declare(strict_types=1);

$qrNamespaceMap = [
    "chillerlan\\QRCode\\" => __DIR__ . "/../libs/chillerlan/php-qrcode/",
    "chillerlan\\Settings\\" => __DIR__ . "/../libs/chillerlan/php-settings-container/",
];

spl_autoload_register(static function (string $class) use ($qrNamespaceMap): void {
    foreach ($qrNamespaceMap as $prefix => $baseDir) {
        if (strncmp($class, $prefix, strlen($prefix)) !== 0) {
            continue;
        }

        $relativeClass = substr($class, strlen($prefix));
        if ($relativeClass === false || $relativeClass === "") {
            return;
        }

        $filePath = $baseDir . str_replace("\\", "/", $relativeClass) . ".php";
        if (is_file($filePath)) {
            require_once $filePath;
        }

        return;
    }
});
