<?php
if( !defined( 'ABSPATH' ) )  exit; // Exit if accessed directly.

// Ensure DB_Setup class is loaded for activation
require_once UNLOCKAFE_INCLUDE_PATH . 'Classes/DB_Setup.php';

spl_autoload_register(function ($class) {
    // project-specific namespace prefix
    $prefix = 'Unlockafe_addons\\';

    // base directory for the namespace prefix
    $base_dir = UNLOCKAFE_INCLUDE_PATH;

    // does the class use the namespace prefi
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        // no, move to the next registered autoloader
        return;
    }

    // get the relative class name
    $relative_class = substr($class, $len);

    // replace the namespace prefix with the base directory, replace namespace
    // separators with directory separators in the relative class name, append
    // with .php
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
    
    // if the file exists, require it
    if (file_exists($file)) {
        require $file;
    }
});