$literal) { $regex .= ($i > 0 ? '.*' : '') . preg_quote($literal, '#'); } return preg_match('#^' . $regex . '/?$#i', $path) === 1; } private static function normalize(string $pattern): string { $pattern = trim($pattern); if (!str_starts_with($pattern, '/')) { $pattern = '/' . $pattern; } $trimmed = rtrim($pattern, '/'); return $trimmed === '' ? '/' : $trimmed; } }