<?php

/**
 * Auto-loads a class file based on the given class name.
 *
 * @param string $className The name of the class to load.
 * @return void
 * @throws Exception If the class file is not found.
 */
spl_autoload_register(function ($className): void
{
    if (strpos($className, 'classes\\') !== false)
    {
        $classesFolder = __DIR__. '/';
    }
    else
    {
        $classesFolder = __DIR__ . '/classes/';
    }

    $filePath = $classesFolder . $className . '.php';
    $filePath = str_replace('\\', '/', $filePath);

    try
    {
        if (file_exists($filePath))
        {
            require_once $filePath;
        }
        else
        {
            exit('Missing class file');
        }
    }
    catch (Exception $error)
    {
        throw new Exception( 'Missing class file ' . $error->getMessage());
    }
});
