/** * * @param Exception|Throwable $exception */ private function reportAndThrow($exception) { if (headers_sent() === false && DebugR::isEnabled()) { if ($exception->getFile()) { $file = preg_replace('/^' . preg_quote(dirname(\Sledgehammer\VENDOR_DIR), '/') . '/', '', $exception->getFile()); $location = "\nin " . $file . ' on line ' . $exception->getLine(); } else { $location = ''; } DebugR::warning(get_class($exception) . "\n" . $exception->getMessage() . $location); } throw $exception; }
/** * De fout afhandelen volgens de afhandel opties (email, log, html). * * @param int $type E_USER_NOTICE, E_USER_ERROR, enz * @param string $message De foutmelding * @param mixed $information Extra informatie voor de fout. bv array('Tip' => 'Controleer ...') */ private function process($type, $message, $information = null) { if ($this->isProcessing) { echo '<span style="color:red">[ErrorHandler failure]'; if ($this->html && is_string($message)) { // show error? if ($message === '__UNCAUGHT_EXCEPTION__' && $this->isThrowable($type)) { echo ' ', htmlentities($type->getMessage() . ' in ' . $type->getFile() . ' on line ' . $type->getLine()); } else { echo ' ', htmlentities($message); } } echo ' </span>'; error_log('ErrorHandler failure: ' . $message); return; } $this->isProcessing = true; if ($this->debugR) { $this->debugR = headers_sent() === false; // Update debugr setting. } if ($this->log || $this->cli || $this->debugR) { if (self::isThrowable($type)) { $error_message = get_class($type) . ': ' . $type->getMessage(); } else { $error_message = $this->error_types[$type] . ': ' . $message; } $location = $this->resolveLocation(); if ($location) { $error_message .= ' in ' . $location['file'] . ' on line ' . $location['line']; } if ($this->log) { error_log($error_message); } if ($this->debugR) { if (class_exists('Sledgehammer\\Core\\Debug\\DebugR', false) === false) { require_once __DIR__ . '/DebugR.php'; } if (class_exists('Sledgehammer\\Core\\Json', false) === false) { require_once __DIR__ . '/../Json.php'; } if (self::isThrowable($type) || in_array($type, array(E_USER_ERROR, E_ERROR, 'EXCEPTION'))) { DebugR::error($error_message); } else { DebugR::warning($error_message); } } } // Limiet contoleren if ($this->email) { // Een foutrapport via email versturen? $limit = $this->importEmailLimit(); if ($limit < 1) { // Is de limiet bereikt? $this->email = false; // Niet emailen } } $buffer = $this->email || $this->debugR; if ($buffer) { // store the html of the error-report in a buffer ob_start(); } elseif (!$this->html) { // No html version required? $this->isProcessing = false; return; // Processing is complete } self::render($type, $message, $information); if ($buffer) { $html = ob_get_clean(); if ($this->debugR) { DebugR::html($html); } if ($this->email) { // email versturen? // Headers voor de email met HTML indeling $headers = "MIME-Version: 1.0\n"; $headers .= 'Content-type: text/html; charset=' . Framework::$charset . "\n"; $headers .= 'From: ' . $this->fromEmail() . "\n"; if (self::isThrowable($type)) { $subject = get_class($type) . ': ' . $type->getMessage(); if ($message === '__UNCAUGHT_EXCEPTION__') { $subject = ' Uncaught ' . $subject; } } else { $subject = $this->error_types[$type] . ': ' . $message; } if (function_exists('mail') && !mail($this->email, $subject, '<html><body style="background-color: #fcf8e3">' . $html . "</body></html>\n", $headers)) { error_log('The ' . self::class . ' was unable to email the report.'); } } if ($this->html) { if ($this->headers && headers_sent() === false) { if (function_exists('http_response_code')) { // PHP 5.4 if (http_response_code() === 200) { http_response_code(500); } } header('Content-Type: text/html; charset=' . Framework::$charset); } echo $html; // buffer weergeven if (ob_get_level() === 0) { flush(); } } } if ($this->cli) { echo '[', date('Y-m-d H:i:s'), '] ', $error_message, "\n"; } $this->isProcessing = false; }