<?php
$rootPath = defined('CIX_ROOT') ? CIX_ROOT : dirname(__DIR__);

spl_autoload_register(function (string $class) use ($rootPath): void {
    $prefix = 'App\\';
    if (str_starts_with($class, $prefix)) {
        $relative = substr($class, strlen($prefix));
        $file = $rootPath . '/app/' . str_replace('\\', '/', $relative) . '.php';
        if (file_exists($file)) {
            require_once $file;
        }
    }
});

$composerAutoload = $rootPath . '/vendor/autoload.php';
if (file_exists($composerAutoload)) {
    require_once $composerAutoload;
}

$bundledAutoload = $rootPath . '/app/Libraries/autoload.php';
if (file_exists($bundledAutoload)) {
    require_once $bundledAutoload;
}

require_once $rootPath . '/app/Helpers/functions.php';
