luya\traits\ErrorHandlerTrait::getExceptionArray PHP Method

getExceptionArray() public method

Get an readable array to transfer from an exception
public getExceptionArray ( mixed $exception ) : array
$exception mixed Exception object
return array An array with transformed exception data
    public function getExceptionArray($exception)
    {
        $_message = 'Uknonwn exception object, not instance of \\Exception.';
        $_file = 'unknown';
        $_line = 0;
        $_trace = [];
        $_previousException = [];
        if (is_object($exception)) {
            $prev = $exception->getPrevious();
            if (!empty($prev)) {
                $_previousException = ['message' => $prev->getMessage(), 'file' => $prev->getFile(), 'line' => $prev->getLine(), 'trace' => $this->buildTrace($prev)];
            }
            $_trace = $this->buildTrace($exception);
            $_message = $exception->getMessage();
            $_file = $exception->getFile();
            $_line = $exception->getLine();
        } elseif (is_string($exception)) {
            $_message = 'exception string: ' . $exception;
        } elseif (is_array($exception)) {
            $_message = isset($exception['message']) ? $exception['message'] : 'exception array dump: ' . print_r($exception, true);
            $_file = isset($exception['file']) ? $exception['file'] : __FILE__;
            $_line = isset($exception['line']) ? $exception['line'] : __LINE__;
        }
        return ['message' => $_message, 'file' => $_file, 'line' => $_line, 'requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null, 'serverName' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null, 'date' => date('d.m.Y H:i'), 'trace' => $_trace, 'previousException' => $_previousException, 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null, 'get' => isset($_GET) ? $_GET : [], 'post' => isset($_POST) ? $_POST : [], 'session' => isset($_SESSION) ? $_SESSION : [], 'server' => isset($_SERVER) ? $_SERVER : []];
    }