function error($code, $text = '', array $trace = NULL, $level = 0)
{
$prior = $this->hive['ERROR'];
$header = $this->status($code);
$req = $this->hive['VERB'] . ' ' . $this->hive['PATH'];
if (!$text) {
$text = 'HTTP ' . $code . ' (' . $req . ')';
}
error_log($text);
$trace = $this->trace($trace);
foreach (explode("\n", $trace) as $nexus) {
if ($nexus) {
error_log($nexus);
}
}
if ($highlight = !$this->hive['CLI'] && !$this->hive['AJAX'] && $this->hive['HIGHLIGHT'] && is_file($css = __DIR__ . '/' . self::CSS)) {
$trace = $this->highlight($trace);
}
$this->hive['ERROR'] = ['status' => $header, 'code' => $code, 'text' => $text, 'trace' => $trace, 'level' => $level];
$this->expire(-1);
$handler = $this->hive['ONERROR'];
$this->hive['ONERROR'] = NULL;
$eol = "\n";
if ((!$handler || $this->call($handler, [$this, $this->hive['PARAMS']], 'beforeroute,afterroute') === FALSE) && !$prior && !$this->hive['CLI'] && !$this->hive['QUIET']) {
echo $this->hive['AJAX'] ? json_encode($this->hive['ERROR']) : '<!DOCTYPE html>' . $eol . '<html>' . $eol . '<head>' . '<title>' . $code . ' ' . $header . '</title>' . ($highlight ? '<style>' . $this->read($css) . '</style>' : '') . '</head>' . $eol . '<body>' . $eol . '<h1>' . $header . '</h1>' . $eol . '<p>' . $this->encode($text ?: $req) . '</p>' . $eol . ($this->hive['DEBUG'] ? '<pre>' . $trace . '</pre>' . $eol : '') . '</body>' . $eol . '</html>';
}
if ($this->hive['HALT']) {
die;
}
}