ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Whoops\Exception\Inspector Class Reference
+ Collaboration diagram for Whoops\Exception\Inspector:

Public Member Functions

 __construct ($exception)
 
 getException ()
 
 getExceptionName ()
 
 getExceptionMessage ()
 
 getExceptionDocrefUrl ()
 Returns a url to the php-manual related to the underlying error - when available. More...
 
 hasPreviousException ()
 Does the wrapped Exception has a previous Exception? More...
 
 getPreviousExceptionInspector ()
 Returns an Inspector for a previous Exception, if any. More...
 
 getFrames ()
 Returns an iterator for the inspected exception's frames. More...
 

Protected Member Functions

 getTrace ($e)
 Gets the backtrace from an exception. More...
 
 getFrameFromException ($exception)
 Given an exception, generates an array in the format generated by Exception::getTrace() More...
 
 getFrameFromError (ErrorException $exception)
 Given an error, generates an array in the format generated by ErrorException. More...
 
 isValidNextFrame (array $frame)
 Determine if the frame can be used to fill in previous frame's missing info happens for call_user_func and call_user_func_array usages (PHP Bug #44428) More...
 

Private Member Functions

 extractDocrefUrl ($message)
 

Private Attributes

 $exception
 
 $frames
 
 $previousExceptionInspector
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

Whoops\Exception\Inspector::__construct (   $exception)
Parameters
\Throwable$exceptionThe exception to inspect

Definition at line 31 of file Inspector.php.

References Whoops\Exception\Inspector\$exception.

32  {
33  $this->exception = $exception;
34  }

Member Function Documentation

◆ extractDocrefUrl()

Whoops\Exception\Inspector::extractDocrefUrl (   $message)
private

Definition at line 70 of file Inspector.php.

References $message.

Referenced by Whoops\Exception\Inspector\getExceptionDocrefUrl(), and Whoops\Exception\Inspector\getExceptionMessage().

71  {
72  $docref = [
73  'message' => $message,
74  'url' => null,
75  ];
76 
77  // php embbeds urls to the manual into the Exception message with the following ini-settings defined
78  // http://php.net/manual/en/errorfunc.configuration.php#ini.docref-root
79  if (!ini_get('html_errors') || !ini_get('docref_root')) {
80  return $docref;
81  }
82 
83  $pattern = "/\[<a href='([^']+)'>(?:[^<]+)<\/a>\]/";
84  if (preg_match($pattern, $message, $matches)) {
85  // -> strip those automatically generated links from the exception message
86  $docref['message'] = preg_replace($pattern, '', $message, 1);
87  $docref['url'] = $matches[1];
88  }
89 
90  return $docref;
91  }
catch(Exception $e) $message
+ Here is the caller graph for this function:

◆ getException()

Whoops\Exception\Inspector::getException ( )
Returns

Definition at line 39 of file Inspector.php.

References Whoops\Exception\Inspector\$exception.

Referenced by Whoops\Exception\Formatter\formatExceptionPlain().

40  {
41  return $this->exception;
42  }
+ Here is the caller graph for this function:

◆ getExceptionDocrefUrl()

Whoops\Exception\Inspector::getExceptionDocrefUrl ( )

Returns a url to the php-manual related to the underlying error - when available.

Returns
string|null

Definition at line 65 of file Inspector.php.

References Whoops\Exception\Inspector\extractDocrefUrl().

66  {
67  return $this->extractDocrefUrl($this->exception->getMessage())['url'];
68  }
+ Here is the call graph for this function:

◆ getExceptionMessage()

Whoops\Exception\Inspector::getExceptionMessage ( )
Returns
string

Definition at line 55 of file Inspector.php.

References Whoops\Exception\Inspector\extractDocrefUrl().

56  {
57  return $this->extractDocrefUrl($this->exception->getMessage())['message'];
58  }
+ Here is the call graph for this function:

◆ getExceptionName()

Whoops\Exception\Inspector::getExceptionName ( )
Returns
string

Definition at line 47 of file Inspector.php.

Referenced by Whoops\Exception\Formatter\formatExceptionPlain().

48  {
49  return get_class($this->exception);
50  }
+ Here is the caller graph for this function:

◆ getFrameFromError()

Whoops\Exception\Inspector::getFrameFromError ( ErrorException  $exception)
protected

Given an error, generates an array in the format generated by ErrorException.

Parameters
ErrorException$exception
Returns
array

Definition at line 243 of file Inspector.php.

244  {
245  return [
246  'file' => $exception->getFile(),
247  'line' => $exception->getLine(),
248  'class' => null,
249  'args' => [],
250  ];
251  }

◆ getFrameFromException()

Whoops\Exception\Inspector::getFrameFromException (   $exception)
protected

Given an exception, generates an array in the format generated by Exception::getTrace()

Parameters
\Throwable$exception
Returns
array

Definition at line 225 of file Inspector.php.

References Whoops\Exception\Inspector\$exception.

Referenced by Whoops\Exception\Inspector\getFrames().

226  {
227  return [
228  'file' => $exception->getFile(),
229  'line' => $exception->getLine(),
230  'class' => get_class($exception),
231  'args' => [
232  $exception->getMessage(),
233  ],
234  ];
235  }
+ Here is the caller graph for this function:

◆ getFrames()

Whoops\Exception\Inspector::getFrames ( )

Returns an iterator for the inspected exception's frames.

Returns

Definition at line 125 of file Inspector.php.

References Whoops\Exception\Inspector\$frames, $i, Whoops\Exception\Inspector\getFrameFromException(), Whoops\Exception\Inspector\getPreviousExceptionInspector(), Whoops\Exception\Inspector\getTrace(), and Whoops\Exception\Inspector\isValidNextFrame().

Referenced by Whoops\Exception\Formatter\formatExceptionPlain().

126  {
127  if ($this->frames === null) {
128  $frames = $this->getTrace($this->exception);
129 
130  // Fill empty line/file info for call_user_func_array usages (PHP Bug #44428)
131  foreach ($frames as $k => $frame) {
132  if (empty($frame['file'])) {
133  // Default values when file and line are missing
134  $file = '[internal]';
135  $line = 0;
136 
137  $next_frame = !empty($frames[$k + 1]) ? $frames[$k + 1] : [];
138 
139  if ($this->isValidNextFrame($next_frame)) {
140  $file = $next_frame['file'];
141  $line = $next_frame['line'];
142  }
143 
144  $frames[$k]['file'] = $file;
145  $frames[$k]['line'] = $line;
146  }
147  }
148 
149  // Find latest non-error handling frame index ($i) used to remove error handling frames
150  $i = 0;
151  foreach ($frames as $k => $frame) {
152  if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) {
153  $i = $k;
154  }
155  }
156 
157  // Remove error handling frames
158  if ($i > 0) {
159  array_splice($frames, 0, $i);
160  }
161 
162  $firstFrame = $this->getFrameFromException($this->exception);
163  array_unshift($frames, $firstFrame);
164 
165  $this->frames = new FrameCollection($frames);
166 
167  if ($previousInspector = $this->getPreviousExceptionInspector()) {
168  // Keep outer frame on top of the inner one
169  $outerFrames = $this->frames;
170  $newFrames = clone $previousInspector->getFrames();
171  // I assume it will always be set, but let's be safe
172  if (isset($newFrames[0])) {
173  $newFrames[0]->addComment(
174  $previousInspector->getExceptionMessage(),
175  'Exception message:'
176  );
177  }
178  $newFrames->prependFrames($outerFrames->topDiff($newFrames));
179  $this->frames = $newFrames;
180  }
181  }
182 
183  return $this->frames;
184  }
getFrameFromException($exception)
Given an exception, generates an array in the format generated by Exception::getTrace() ...
Definition: Inspector.php:225
isValidNextFrame(array $frame)
Determine if the frame can be used to fill in previous frame&#39;s missing info happens for call_user_fun...
Definition: Inspector.php:260
getPreviousExceptionInspector()
Returns an Inspector for a previous Exception, if any.
Definition: Inspector.php:107
getTrace($e)
Gets the backtrace from an exception.
Definition: Inspector.php:194
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPreviousExceptionInspector()

Whoops\Exception\Inspector::getPreviousExceptionInspector ( )

Returns an Inspector for a previous Exception, if any.

Todo:
Clean this up a bit, cache stuff a bit better.
Returns
Inspector

Definition at line 107 of file Inspector.php.

References Whoops\Exception\Inspector\$previousExceptionInspector.

Referenced by Whoops\Exception\Inspector\getFrames().

108  {
109  if ($this->previousExceptionInspector === null) {
110  $previousException = $this->exception->getPrevious();
111 
112  if ($previousException) {
113  $this->previousExceptionInspector = new Inspector($previousException);
114  }
115  }
116 
118  }
+ Here is the caller graph for this function:

◆ getTrace()

Whoops\Exception\Inspector::getTrace (   $e)
protected

Gets the backtrace from an exception.

If xdebug is installed

Parameters
\Throwable$exception
Returns
array

Definition at line 194 of file Inspector.php.

References Whoops\Util\Misc\isLevelFatal().

Referenced by Whoops\Exception\Inspector\getFrames().

195  {
196  $traces = $e->getTrace();
197 
198  // Get trace from xdebug if enabled, failure exceptions only trace to the shutdown handler by default
199  if (!$e instanceof \ErrorException) {
200  return $traces;
201  }
202 
203  if (!Misc::isLevelFatal($e->getSeverity())) {
204  return $traces;
205  }
206 
207  if (!extension_loaded('xdebug') || !xdebug_is_enabled()) {
208  return [];
209  }
210 
211  // Use xdebug to get the full stack trace and remove the shutdown handler stack trace
212  $stack = array_reverse(xdebug_get_function_stack());
213  $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
214  $traces = array_diff_key($stack, $trace);
215 
216  return $traces;
217  }
static isLevelFatal($level)
Determine if an error level is fatal (halts execution)
Definition: Misc.php:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPreviousException()

Whoops\Exception\Inspector::hasPreviousException ( )

Does the wrapped Exception has a previous Exception?

Returns
bool

Definition at line 97 of file Inspector.php.

98  {
99  return $this->previousExceptionInspector || $this->exception->getPrevious();
100  }

◆ isValidNextFrame()

Whoops\Exception\Inspector::isValidNextFrame ( array  $frame)
protected

Determine if the frame can be used to fill in previous frame's missing info happens for call_user_func and call_user_func_array usages (PHP Bug #44428)

Parameters
array$frame
Returns
bool

Definition at line 260 of file Inspector.php.

Referenced by Whoops\Exception\Inspector\getFrames().

261  {
262  if (empty($frame['file'])) {
263  return false;
264  }
265 
266  if (empty($frame['line'])) {
267  return false;
268  }
269 
270  if (empty($frame['function']) || !stristr($frame['function'], 'call_user_func')) {
271  return false;
272  }
273 
274  return true;
275  }
+ Here is the caller graph for this function:

Field Documentation

◆ $exception

Whoops\Exception\Inspector::$exception
private

◆ $frames

Whoops\Exception\Inspector::$frames
private

Definition at line 21 of file Inspector.php.

Referenced by Whoops\Exception\Inspector\getFrames().

◆ $previousExceptionInspector

Whoops\Exception\Inspector::$previousExceptionInspector
private

The documentation for this class was generated from the following file: