static function shutdown($error = '', $content = null, $headers = array()) { if (self::$shutdown) { return self::log("shutdown in progress (another shutdown call)"); } self::$shutdown = 1; if ($error) { self::log("shutdown by '" . strip_tags($error) . "'"); } $printed = ob_get_clean(); // needs to be called for the buffer to properly reset (ob_clean is not enough) if (is_null($content)) { $content = $printed; } $type = isset($headers['Content-type']) ? $headers['Content-type'] : 'text/html'; if ($type === 'text/html') { $template = file_get_contents(__DIR__ . "/html/index.html") ?: "<html><body>{{body}}</body></html>"; $content = str_replace("{{body}}", $content, $template); } die($content); }