Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
 
7
namespace Whoops\Exception;
8
 
688 lars 9
use Whoops\Inspector\InspectorInterface;
10
 
148 lars 11
class Formatter
12
{
13
    /**
14
     * Returns all basic information about the exception in a simple array
15
     * for further convertion to other languages
688 lars 16
     * @param  InspectorInterface $inspector
17
     * @param  bool               $shouldAddTrace
18
     * @param  array<callable>    $frameFilters
148 lars 19
     * @return array
20
     */
688 lars 21
    public static function formatExceptionAsDataArray(InspectorInterface $inspector, $shouldAddTrace, array $frameFilters = [])
148 lars 22
    {
23
        $exception = $inspector->getException();
24
        $response = [
25
            'type'    => get_class($exception),
26
            'message' => $exception->getMessage(),
27
            'code'    => $exception->getCode(),
28
            'file'    => $exception->getFile(),
29
            'line'    => $exception->getLine(),
30
        ];
31
 
32
        if ($shouldAddTrace) {
688 lars 33
            $frames    = $inspector->getFrames($frameFilters);
148 lars 34
            $frameData = [];
35
 
36
            foreach ($frames as $frame) {
37
                /** @var Frame $frame */
38
                $frameData[] = [
39
                    'file'     => $frame->getFile(),
40
                    'line'     => $frame->getLine(),
41
                    'function' => $frame->getFunction(),
42
                    'class'    => $frame->getClass(),
43
                    'args'     => $frame->getArgs(),
44
                ];
45
            }
46
 
47
            $response['trace'] = $frameData;
48
        }
49
 
50
        return $response;
51
    }
52
 
688 lars 53
    public static function formatExceptionPlain(InspectorInterface $inspector)
148 lars 54
    {
55
        $message = $inspector->getException()->getMessage();
56
        $frames = $inspector->getFrames();
57
 
58
        $plain = $inspector->getExceptionName();
59
        $plain .= ' thrown with message "';
60
        $plain .= $message;
61
        $plain .= '"'."\n\n";
62
 
63
        $plain .= "Stacktrace:\n";
64
        foreach ($frames as $i => $frame) {
65
            $plain .= "#". (count($frames) - $i - 1). " ";
66
            $plain .= $frame->getClass() ?: '';
67
            $plain .= $frame->getClass() && $frame->getFunction() ? ":" : "";
68
            $plain .= $frame->getFunction() ?: '';
69
            $plain .= ' in ';
70
            $plain .= ($frame->getFile() ?: '<#unknown>');
71
            $plain .= ':';
72
            $plain .= (int) $frame->getLine(). "\n";
73
        }
74
 
75
        return $plain;
76
    }
77
}