added skipping of library classes in error traces

This commit is contained in:
Steffen Schröder 2014-06-19 17:54:37 +02:00
parent 402bbc1971
commit 1b9097812e

View File

@ -213,9 +213,10 @@ class ErrorHandler {
$traceString = ''; $traceString = '';
$stepCount = 0; $stepCount = 0;
foreach ($backtrace as $traceStep) { foreach ($backtrace as $traceStep) {
$skipStep = $this->shouldSkipTraceStep($traceStep);
$traceString .= '#' . $stepCount . ': '; $traceString .= '#' . $stepCount . ': ';
if (isset($traceStep['class'])) { if (isset($traceStep['class'])) {
if (!$sourceClass && strpos($traceStep['class'], '\\FaultException') === false && strpos($traceStep['class'], '\\ErrorHandler') === false) { if (!$skipStep && !$this->isIgnoredSourceClass($traceStep['class'])) {
$sourceClass = $traceStep['class']; $sourceClass = $traceStep['class'];
} }
$traceString .= $traceStep['class']; $traceString .= $traceStep['class'];
@ -225,16 +226,16 @@ class ErrorHandler {
} }
if (isset($traceStep['function'])) { if (isset($traceStep['function'])) {
$traceString .= $traceStep['function'] . '('; $traceString .= $traceStep['function'] . '(';
if (isset($traceStep['args'])) { if (isset($traceStep['args']) && !$skipStep) {
$traceString .= $this->parseArgumentsArray($traceStep['args']); $traceString .= $this->parseArgumentsArray($traceStep['args']);
} }
$traceString .= ')'; $traceString .= ')';
} }
if (isset($traceStep['file'])) { if (isset($traceStep['file']) && !$skipStep) {
$traceString .= ' in File '; $traceString .= ' in File ';
$traceString .= $traceStep['file']; $traceString .= $traceStep['file'];
} }
if (isset($traceStep['line'])) { if (isset($traceStep['line']) && !$skipStep) {
$traceString .= ' on Line '; $traceString .= ' on Line ';
$traceString .= $traceStep['line']; $traceString .= $traceStep['line'];
} }
@ -249,6 +250,35 @@ class ErrorHandler {
return $traceString; return $traceString;
} }
/**
* Check if the given Trace Step should be skipped
*
* @param array $traceStep
* @return bool
*/
private function shouldSkipTraceStep(array $traceStep) {
if (isset($traceStep['class'])) {
$skippedClasses = array('Symfony', 'cURL');
foreach ($skippedClasses as $skippedClass) {
if (strpos($traceStep['class'], $skippedClass) !== false) {
return true;
}
}
}
return false;
}
/**
* Check if the given Class Name should be ignored as possible Error Source Class
*
* @param string $class
* @return bool
*/
private function isIgnoredSourceClass($class) {
return (!$class || strpos($class, '\\FaultException') !== false || strpos($class, '\\ErrorHandler') !== false);
}
/** /**
* Build a String from an Arguments Array * Build a String from an Arguments Array
* *