<?php

// Global-namespace polyfills for minimal PHP builds (rare on cPanel, but
// cheap insurance). Byte-length fallbacks are acceptable for validation.

if (!function_exists('mb_strlen')) {
    function mb_strlen(string $string, ?string $encoding = null): int
    {
        return strlen($string);
    }
}

if (!function_exists('mb_substr')) {
    function mb_substr(string $string, int $start, ?int $length = null, ?string $encoding = null): string
    {
        return $length === null ? substr($string, $start) : substr($string, $start, $length);
    }
}

if (!function_exists('mime_content_type')) {
    function mime_content_type(string $filename): string|false
    {
        // Minimal image sniffing for uploads when fileinfo is unavailable.
        $info = @getimagesize($filename);
        return $info['mime'] ?? false;
    }
}
