<?php
// Autoloader manual untuk PhpSpreadsheet, Composer\Pcre, SimpleCache, dan ZipStream
function autoload($class) {
    $baseDir = __DIR__ . '/vendor/';  // Direktori vendor Anda
    
    // Mencari file di folder ZipStream
    if (strpos($class, 'ZipStream\\') === 0) {
        $class = str_replace('ZipStream\\', '', $class);
        $file = $baseDir . 'ZipStream-PHP/src/' . $class . '.php';
    }
    // Mencari file di folder PhpSpreadsheet
    elseif (strpos($class, 'PhpOffice\\PhpSpreadsheet\\') === 0) {
        $class = str_replace('PhpOffice\\PhpSpreadsheet\\', '', $class);
        $file = $baseDir . 'PhpSpreadsheet/src/PhpSpreadsheet/' . $class . '.php';
    } 
    // Mencari file di folder Composer\Pcre
    elseif (strpos($class, 'Composer\\Pcre\\') === 0) {
        $class = str_replace('Composer\\Pcre\\', '', $class);
        $file = $baseDir . 'pcre-main/src/' . $class . '.php';
    }
    // Mencari file di folder SimpleCache
    elseif (strpos($class, 'Psr\\SimpleCache\\') === 0) {
        $class = str_replace('Psr\\SimpleCache\\', '', $class);
        $file = $baseDir . 'simple-cache-master/src/' . $class . '.php';
    } else {
        $file = null;  // Tidak ditemukan, biarkan autoloader lain yang mengurusnya
    }

    // Debugging
    if ($file && file_exists($file)) {
        require_once $file;
    } else {
        echo "File tidak ditemukan: $file\n"; // Menampilkan file yang tidak ditemukan
    }
}

// Daftarkan autoloader
spl_autoload_register('autoload');
