setReportInfo($reportUrl, $reportSign); } public function setReportInfo(?string $reportUrl = null, ?string $reportSign = null): void { $this->reportUrl = $reportUrl; $this->reportSign = $reportSign; } public function handle() { echo $this->html( $this->report() ? 'Information about this error has been sent to the devs.' : 'Report what you were trying to a developer.' ); return Handler::QUIT; } public function contentType(): string { return 'text/html'; } public function html(string $text): string { return << Something broke!
Something broke!

{$text}

HTML; } private function report(): bool { if (!mb_strlen($this->reportUrl) || !($curl = curl_init($this->reportUrl))) { return false; } $json = json_encode([ 'git' => [ 'tag' => git_tag(), 'hash' => git_commit_hash(true), ], 'misuzu' => [ 'trace_txt' => $this->getException()->getTraceAsString(), 'directory' => MSZ_ROOT, ], 'exception' => Formatter::formatExceptionAsDataArray( $this->getInspector(), $this ), ]); $headers = [ 'Content-Type: application/json;charset=utf-8', ]; if (mb_strlen($this->reportSign)) { $headers[] = 'X-Misuzu-Signature: sha256=' . hash_hmac('sha256', $json, $this->reportSign); } $setOpts = curl_setopt_array($curl, [ CURLOPT_TCP_NODELAY => true, CURLOPT_POSTFIELDS => $json, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => false, ]); if (!$setOpts) { return false; } return curl_exec($curl) !== false; } }