<?php
// Minimal PSR-4 autoloader for the vendored dompdf + its 3 required
// dependencies (masterminds/html5, phenx/php-font-lib, phenx/php-svg-lib).
// Composer is not available in this environment, so these packages were
// downloaded directly from their GitHub release tags and are loaded here
// with a hand-written autoloader instead of vendor/autoload.php.
spl_autoload_register(function (string $class): void {
    // dompdf's lib/ classmap: Cpdf.php declares `namespace Dompdf;` but
    // physically lives in lib/, not src/, so it needs special-casing
    // before the PSR-4 prefix loop below.
    if ($class === 'Dompdf\\Cpdf') {
        require __DIR__ . '/dompdf/lib/Cpdf.php';
        return;
    }
    static $prefixes = [
        'Dompdf\\'    => __DIR__ . '/dompdf/src/',
        'Masterminds\\' => __DIR__ . '/html5-php/src/',
        'FontLib\\'   => __DIR__ . '/php-font-lib/src/FontLib/',
        'Svg\\'       => __DIR__ . '/php-svg-lib/src/Svg/',
    ];
    foreach ($prefixes as $prefix => $baseDir) {
        if (strncmp($class, $prefix, strlen($prefix)) === 0) {
            $relative = substr($class, strlen($prefix));
            $path = $baseDir . str_replace('\\', '/', $relative) . '.php';
            if (is_file($path)) { require $path; return; }
        }
    }
});
