ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Formatter.php
Go to the documentation of this file.
1 <?php
7 namespace Whoops\Exception;
8 
9 class Formatter
10 {
18  public static function formatExceptionAsDataArray(Inspector $inspector, $shouldAddTrace)
19  {
20  $exception = $inspector->getException();
21  $response = [
22  'type' => get_class($exception),
23  'message' => $exception->getMessage(),
24  'file' => $exception->getFile(),
25  'line' => $exception->getLine(),
26  ];
27 
28  if ($shouldAddTrace) {
29  $frames = $inspector->getFrames();
30  $frameData = [];
31 
32  foreach ($frames as $frame) {
34  $frameData[] = [
35  'file' => $frame->getFile(),
36  'line' => $frame->getLine(),
37  'function' => $frame->getFunction(),
38  'class' => $frame->getClass(),
39  'args' => $frame->getArgs(),
40  ];
41  }
42 
43  $response['trace'] = $frameData;
44  }
45 
46  return $response;
47  }
48 
49  public static function formatExceptionPlain(Inspector $inspector)
50  {
51  $message = $inspector->getException()->getMessage();
52  $frames = $inspector->getFrames();
53 
54  $plain = $inspector->getExceptionName();
55  $plain .= ' thrown with message "';
56  $plain .= $message;
57  $plain .= '"'."\n\n";
58 
59  $plain .= "Stacktrace:\n";
60  foreach ($frames as $i => $frame) {
61  $plain .= "#". (count($frames) - $i - 1). " ";
62  $plain .= $frame->getClass() ?: '';
63  $plain .= $frame->getClass() && $frame->getFunction() ? ":" : "";
64  $plain .= $frame->getFunction() ?: '';
65  $plain .= ' in ';
66  $plain .= ($frame->getFile() ?: '<#unknown>');
67  $plain .= ':';
68  $plain .= (int) $frame->getLine(). "\n";
69  }
70 
71  return $plain;
72  }
73 }
getFrames()
Returns an iterator for the inspected exception&#39;s frames.
Definition: Inspector.php:125
static formatExceptionPlain(Inspector $inspector)
Definition: Formatter.php:49
Whoops - php errors for cool kids.