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