ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Inspector.php
Go to the documentation of this file.
1<?php
7namespace Whoops\Exception;
8
9use Exception;
10
12{
16 private $exception;
17
21 private $frames;
22
27
31 public function __construct(Exception $exception)
32 {
33 $this->exception = $exception;
34 }
35
39 public function getException()
40 {
41 return $this->exception;
42 }
43
47 public function getExceptionName()
48 {
49 return get_class($this->exception);
50 }
51
55 public function getExceptionMessage()
56 {
57 return $this->exception->getMessage();
58 }
59
64 public function hasPreviousException()
65 {
66 return $this->previousExceptionInspector || $this->exception->getPrevious();
67 }
68
75 {
76 if ($this->previousExceptionInspector === null) {
77 $previousException = $this->exception->getPrevious();
78
79 if ($previousException) {
80 $this->previousExceptionInspector = new Inspector($previousException);
81 }
82 }
83
85 }
86
92 public function getFrames()
93 {
94 if ($this->frames === null) {
95 $frames = $this->exception->getTrace();
96
97 // If we're handling an ErrorException thrown by Whoops,
98 // get rid of the last frame, which matches the handleError method,
99 // and do not add the current exception to trace. We ensure that
100 // the next frame does have a filename / linenumber, though.
101 if ($this->exception instanceof ErrorException && empty($frames[1]['line'])) {
102 $frames = array($this->getFrameFromError($this->exception));
103 } else {
104 $firstFrame = $this->getFrameFromException($this->exception);
105 array_unshift($frames, $firstFrame);
106 }
107 $this->frames = new FrameCollection($frames);
108
109 if ($previousInspector = $this->getPreviousExceptionInspector()) {
110 // Keep outer frame on top of the inner one
111 $outerFrames = $this->frames;
112 $newFrames = clone $previousInspector->getFrames();
113 // I assume it will always be set, but let's be safe
114 if (isset($newFrames[0])) {
115 $newFrames[0]->addComment(
116 $previousInspector->getExceptionMessage(),
117 'Exception message:'
118 );
119 }
120 $newFrames->prependFrames($outerFrames->topDiff($newFrames));
121 $this->frames = $newFrames;
122 }
123 }
124
125 return $this->frames;
126 }
127
134 protected function getFrameFromException(Exception $exception)
135 {
136 return array(
137 'file' => $exception->getFile(),
138 'line' => $exception->getLine(),
139 'class' => get_class($exception),
140 'args' => array(
141 $exception->getMessage(),
142 ),
143 );
144 }
145
153 {
154 return array(
155 'file' => $exception->getFile(),
156 'line' => $exception->getLine(),
157 'class' => null,
158 'args' => array(),
159 );
160 }
161}
Wraps ErrorException; mostly used for typing (at least now) to easily cleanup the stack trace of redu...
Exposes a fluent interface for dealing with an ordered list of stack-trace frames.
getFrameFromError(ErrorException $exception)
Given an error, generates an array in the format generated by ErrorException.
Definition: Inspector.php:152
getPreviousExceptionInspector()
Returns an Inspector for a previous Exception, if any.
Definition: Inspector.php:74
hasPreviousException()
Does the wrapped Exception has a previous Exception?
Definition: Inspector.php:64
getFrames()
Returns an iterator for the inspected exception's frames.
Definition: Inspector.php:92
getFrameFromException(Exception $exception)
Given an exception, generates an array in the format generated by Exception::getTrace()
Definition: Inspector.php:134
__construct(Exception $exception)
Definition: Inspector.php:31
Whoops - php errors for cool kids.