Builds Airbrake notice from exception.

@param \Throwable|\Exception $exc Exception or class that implements similar interface.
@return array Airbrake notice
766536
public function buildNotice($exc)
    {
        $errors = [];
        while (!empty($exc)) {
            $err = [
                'type' => get_class($exc),
                'message' => $exc->getMessage(),
                'backtrace' => $this->backtrace($exc)
            ];
            array_push($errors, $err);

            if (!is_callable([$exc, 'getPrevious'])) {
                break;
            }

            $exc = $exc->getPrevious();
        }

        $context = $this->context;
        if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) {
            $scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
            $context['url'] = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        }
        if (isset($_SERVER['HTTP_USER_AGENT'])) {
            $context['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
        }
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
            $context['userAddr'] = trim(array_pop($ips));
        } else if (isset($_SERVER['REMOTE_ADDR'])) {
            $context['userAddr'] = $_SERVER['REMOTE_ADDR'];
        }

        $notice = [
            'errors' => $errors,
            'context' => $context,
        ];
        if (!empty($_REQUEST)) {
            $notice['params'] = $_REQUEST;
        }
        if (!empty($_SESSION)) {
            $notice['session'] = $_SESSION;
        }

        return $notice;
    }
131728
function _exceptionHandler($exception)
    {
        $result['message'] = $exception->getMessage();

        if (self::$_config['errors']['exceptionBacktrace']) {
            $result['backtrace'] = $this->convertTrace($exception->getTrace());
        }

        $result['string'] = $exception->getTraceAsString();
        $result['code']   = $exception->getCode();

        if ($this->_isLiteMode()) {
            $this->_dumpRenderLite(PHP_EOL . $result['string'], '** EXCEPTION / ' . $this->_htmlChars($result['message']));

        } else {
            $this->_initAssets(true);
            $this->dump($result, '<b style="color:red;">**</b> EXCEPTION / ' . $this->_htmlChars($result['message']));
        }

        return true;
    }
1116656
public static function getThrowableData($ex, $offset = 0)
    {
        return [
            'message'   => $ex->getMessage(),
            'class'     => get_class($ex),
            'file'      => $ex->getFile(),
            'line'      => $ex->getLine(),
            'code'      => $ex->getCode(),
            'trace'     => static::getTraceElements($ex, $offset),
            'isError'   => $ex instanceof \Error,
            'prev'      => null
        ];
    }
83787
protected function exceptionStackTrace(\Throwable $exception) : array
    {
        $return = [];
        $line = $exception->getLine();
        $file = $exception->getFile();

        $trace = $exception->getTrace();
        foreach (explode("\n", $exception->getTraceAsString()) as $currentLine) {
            $row = explode(' ', $currentLine);

            $stack = ['file' => null];
            $buffer = null;
            $index = trim(array_shift($row), '#');

            foreach ($row as $current) {
                // current file
                if (is_null($stack['file'])) {
                    if (substr($current, -1) === ':') {
                        $stack['file'] = trim($buffer ? $buffer . $current : $current, ':');

                        if (preg_match('`([^\\(]+)\\(([0-9]+)\\)`', $stack['file'], $matches)) {
                            $stack['file'] = $matches[1];
                            $stack['line'] = (int) $matches[2];
                        }
                    } else {
                        $buffer .= $current . ' ';
                    }
                } elseif (!isset($stack['function'])) {
                    $stack['function'] = strstr($current, '(', true);
                    $explodeString = strpos($stack['function'], '::') !== false ? '::' : '->';
                    $explode = explode($explodeString, $stack['function']);

                    if (sizeof($explode) > 1) {
                        $stack['class'] = $explode[0];
                        $stack['type'] = $explodeString;
                        $stack['function'] = $explode[1];

                        if (strpos($stack['class'], '\\') !== false) {
                            $explode = explode('\\', $stack['class']);
                            $stack['class'] = array_pop($explode);
                            $stack['namespace'] = implode('\\', $explode);
                        }
                    } elseif (strpos($stack['function'], '\\') !== false) {
                        $explode = explode('\\', $stack['function']);
                        $stack['function'] = array_pop($explode);
                        $stack['namespace'] = implode('\\', $explode);
                    }

                    $stack['args'] = strstr($current, '(') . ' ';
                } else {
                    $stack['args'] .= $current . ' ';
                }
            }

            if (is_null($stack['file'])) {
                $stack['file'] = $row[0];
            }

            $skip = false;

            // hack to hide error handler
            if (isset($stack['namespace']) && isset($stack['class'])) {
                if ($stack['namespace'] == 'Cawa\Error' && $stack['class'] == 'Handler') {
                    $skip = true;
                }
            }

            // hack to hide backtrace call
            if (isset($stack['function']) && $stack['function'] == 'backtrace') {
                $skip = true;
                $file = $stack['file'];
                $line = (int) $stack['line'];
            }

            if ($skip == false) {
                if (isset($trace[$index]) && isset($trace[$index]['args'])) {
                    $stack['fullargs'] = $trace[$index]['args'];
                }

                $return[] = $stack;
            }
        }

        $return[0]['line'] = $line;
        $return[0]['file'] = $file;

        return $return;
    }
696291
public function getExceptions(\Throwable $exception): array
    {
        $exc = $exception;
        do {
            $exc_data = [
                'value' => $this->serializer->serialize($exc->getMessage()),
                'type' => get_class($exc),
            ];

            /**'exception'
             * Exception::getTrace doesn't store the point at where the exception
             * was thrown, so we have to stuff it in ourselves. Ugh.
             */
            $trace = $exc->getTrace();
            $frame_where_exception_thrown = [
                'file' => $exc->getFile(),
                'line' => $exc->getLine(),
            ];

            array_unshift($trace, $frame_where_exception_thrown);

            $exc_data['stacktrace'] = [
                'frames' => $this->getStackTraceFrames($trace),
            ];

            $exceptions[] = $exc_data;
        } while ($exc = $exc->getPrevious());

        return array_reverse($exceptions);
    }
435656
public static function handleException(\Exception $__exc_objException)
    {
        if (class_exists('\QApplicationBase')) {
            \QApplicationBase::$ErrorFlag = true;
        }

        global $__exc_strType;
        if (isset($__exc_strType)) {
            return;
        } // error was already called, avoid endless looping

        $__exc_strType = "Exception";
        $__exc_errno = $__exc_objException->getCode();
        $__exc_strMessage = $__exc_objException->getMessage();
        //$__exc_strObjectType = $__exc_objReflection->getName();

        if ($__exc_objException instanceof \QCubed\Database\AbstractBase) {
            $__exc_objErrorAttribute = new ErrorAttribute("Database Error Number", $__exc_errno, false);
            $__exc_objErrorAttributeArray[0] = $__exc_objErrorAttribute;

            if ($__exc_objException->Query) {
                $__exc_objErrorAttribute = new ErrorAttribute("Query", $__exc_objException->Query, true);
                $__exc_objErrorAttributeArray[1] = $__exc_objErrorAttribute;
            }
        }

        if ($__exc_objException instanceof \QDataBindException) {
            if ($__exc_objException->Query) {
                $__exc_objErrorAttribute = new ErrorAttribute("Query", $__exc_objException->Query, true);
                $__exc_objErrorAttributeArray[1] = $__exc_objErrorAttribute;
            }
        }

        $__exc_strFilename = $__exc_objException->getFile();
        $__exc_intLineNumber = $__exc_objException->getLine();
        $__exc_strStackTrace = trim($__exc_objException->getTraceAsString());

        if (ob_get_length()) {
            //$__exc_strRenderedPage = ob_get_contents();
            ob_clean();
        }

        // Call to display the Error Page (as defined in configuration.inc.php)
        if (defined('QCUBED_ERROR_PAGE_PHP')) {
            require(__DOCROOT__ . QCUBED_ERROR_PAGE_PHP);
        } else {
            // Error in installer or similar - QCUBED_ERROR_PAGE_PHP constant is not defined yet.
            echo "error: errno: " . $__exc_errno . "<br/>" . $__exc_strMessage . "<br/>" . $__exc_strFilename . ":" . $__exc_intLineNumber . "<br/>" . $__exc_strStackTrace;
        }
        if (!defined('HHVM_VERSION')) {
            exit(); // HHVM bug. Will not display output if this gets executed here.
        }
    }
225836
public function formatException(\Exception $e) {
        $entry = array();

        $entry['class'] = get_class($e);
        $entry['message'] = $e->getMessage();
        $entry['file'] = $e->getFile();
        $entry['line'] = $e->getLine();
        $entry['trace'] = $e->getTraceAsString();

        return $entry;
    }
310726
public static function printException(\Exception $ex)
    {
        $msg="code:".$ex->getCode()
            ."\r\nmessage:".$ex->getMessage()
            ."\r\ntrace:".$ex->getTraceAsString();
        self::printLine($msg);
    }
772599
public function convert(\Exception $ex)
    {
        $exceptions = array();

        do {
            $exceptions[] = $this->convertException($ex);
        } while (null !== $ex = $ex->getPrevious());

        return $exceptions;
    }
639827
public function shellExec($command, $exceptionOnError = true, $tail = ' 2>&1', $exception = ShellException::class)
    {
        $command = $this->filterCommand($command, $tail);
        $this->showCommand($command);

        exec($command, $output, $this->lastStatus);

        $output = $this->filterOutput($output);
        $this->processError($output, $exceptionOnError, $exception);

        return $output;
    }
768
private function createInternalServerError(\Exception $exception)
    {
        $message = sprintf(
            '%s: %s (uncaught exception) at %s line %s',
            get_class($exception),
            $exception->getMessage(),
            $exception->getFile(),
            $exception->getLine()
        );

        $this->logger->error($message, array('exception' => $exception));

        $response = [
            'status'  => 'ERROR',
            'message' => JsonResponse::$statusTexts[JsonResponse::HTTP_INTERNAL_SERVER_ERROR]
        ];

        if ($this->debug) {
            $response['exception'] = $this->formatException($exception);
        }

        return new JsonResponse($response, JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
    }
272530
public function supports(Exception $ex) {
        $instanceof = get_class($ex) === $this->getExceptionClass();
        $extends = is_subclass_of($ex, $this->getExceptionClass());

        return $instanceof || $extends;
    }
705490
protected function getSafeTrace(\Exception $exception)
    {
        if (!$this->debug && !($this->session->isStarted() && $this->session->has('authentication'))) {
            return [];
        }

        $trace = $exception->getTrace();
        foreach ($trace as $key => $value) {
            $trace[$key]['args_safe'] = $this->getSafeArguments($trace[$key]['args']);

            // Don't display the full path, trim 64-char hexadecimal file names.
            if (isset($trace[$key]['file'])) {
                $trace[$key]['file'] = str_replace($this->rootPath, '[root]', $trace[$key]['file']);
                $trace[$key]['file'] = preg_replace('/([0-9a-f]{16})[0-9a-f]{48}/i', '\1…', $trace[$key]['file']);
            }
        }

        return $trace;
    }
1006427
private function serializeException(\Exception $exception)
    {
        return [
            'message' => $exception->getMessage(),
            'code' => $exception->getCode(),
            'trace' => $exception->getTrace(),
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'previous' => null !== $exception->getPrevious() ? $this->serializeException($exception->getPrevious()) : null,
        ];
    }
604586
protected static function makeExceptionContent(\Exception $exception)
    {
        if ($exception instanceof DfException) {
            return ['error' => $exception->toArray()];
        }

        $errorInfo['code'] = ($exception->getCode()) ?: ServiceResponseInterface::HTTP_INTERNAL_SERVER_ERROR;
        $errorInfo['message'] = htmlentities($exception->getMessage());

        if (config('app.debug', false)) {
            $trace = $exception->getTraceAsString();
            $trace = str_replace(["\n", "#"], ["", "<br>"], $trace);
            $traceArray = explode("<br>", $trace);
            $cleanTrace = [];
            foreach ($traceArray as $k => $v) {
                if (!empty($v)) {
                    $cleanTrace[] = $v;
                }
            }
            $errorInfo['trace'] = $cleanTrace;
        }

        return ['error' => $errorInfo];
    }
961593
static function asArray(Exception $e)
    {
        return [
            'exception'   => get_class($e),
            'code'        => $e->getCode(),
            'message'     => $e->getMessage(),
            'file'        => $e->getFile(),
            'line'        => $e->getLine(),
            'hash'        => self::hash($e),
            'status_code' => self::statusCode($e)
        ];
    }
1071082
private function serializeException(\Exception $exception)
    {
        $result = [
            'code'    => $exception->getCode(),
            'message' => $exception->getMessage(),
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine(),
            'trace'   => $exception->getTraceAsString(),
        ];

        if ($exception->getPrevious() !== null) {
            $result['previous'] = $this->serializeException($exception->getPrevious());
        }

        return $result;
    }