Skip to content
Snippets Groups Projects
Commit 161ff26b authored by Olav Morken's avatar Olav Morken
Browse files

Integrate SimpleSAML_Utilities::buildBacktrace() into SimpleSAML_Error_Exception.

Since this function is only used in SimpleSAML_Error_Exception and a
subclass, move it here.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2487 44740490-163a-0410-bde0-09ae8108e29a
parent 75571a81
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ class SimpleSAML_Error_Exception extends Exception {
parent::__construct($message, $code);
$this->backtrace = SimpleSAML_Utilities::buildBacktrace($this);
$this->initBacktrace($this);
if ($cause !== NULL) {
$this->cause = SimpleSAML_Error_Exception::fromException($cause);
......@@ -70,27 +70,44 @@ class SimpleSAML_Error_Exception extends Exception {
/**
* Retrieve the backtrace.
* Load the backtrace from the given exception.
*
* @return array An array where each function call is a single item.
* @param Exception $exception The exception we should fetch the backtrace from.
*/
public function getBacktrace() {
return $this->backtrace;
protected function initBacktrace(Exception $exception) {
$this->backtrace = array();
/* Position in the top function on the stack. */
$pos = $exception->getFile() . ':' . $exception->getLine();
foreach($exception->getTrace() as $t) {
$function = $t['function'];
if(array_key_exists('class', $t)) {
$function = $t['class'] . '::' . $function;
}
$this->backtrace[] = $pos . ' (' . $function . ')';
if(array_key_exists('file', $t)) {
$pos = $t['file'] . ':' . $t['line'];
} else {
$pos = '[builtin]';
}
}
$this->backtrace[] = $pos . ' (N/A)';
}
/**
* Replace the backtrace.
*
* This function is meant for subclasses which needs to replace the backtrace
* of this exception, such as the SimpleSAML_Error_Unserializable class.
* Retrieve the backtrace.
*
* @param array $backtrace The new backtrace.
* @return array An array where each function call is a single item.
*/
protected function setBacktrace($backtrace) {
assert('is_array($backtrace)');
$this->backtrace = $backtrace;
public function getBacktrace() {
return $this->backtrace;
}
......
......@@ -40,8 +40,7 @@ class SimpleSAML_Error_UnserializableException extends SimpleSAML_Error_Exceptio
}
parent::__construct($msg, $code);
$this->setBacktrace(SimpleSAML_Utilities::buildBacktrace($original));
$this->initBacktrace($original);
}
......
......@@ -261,51 +261,6 @@ class SimpleSAML_Utilities {
}
/**
* Build a backtrace.
*
* This function takes in an exception and optionally a start depth, and
* builds a backtrace from that depth. The backtrace is returned as an
* array of strings, where each string represents one level in the stack.
*
* @param Exception $exception The exception.
* @param int $startDepth The depth we should print the backtrace from.
* @return array The backtrace as an array of strings.
*/
public static function buildBacktrace(Exception $exception, $startDepth = 0) {
assert('is_int($startDepth)');
$bt = array();
/* Position in the top function on the stack. */
$pos = $exception->getFile() . ':' . $exception->getLine();
foreach($exception->getTrace() as $t) {
$function = $t['function'];
if(array_key_exists('class', $t)) {
$function = $t['class'] . '::' . $function;
}
$bt[] = $pos . ' (' . $function . ')';
if(array_key_exists('file', $t)) {
$pos = $t['file'] . ':' . $t['line'];
} else {
$pos = '[builtin]';
}
}
$bt[] = $pos . ' (N/A)';
/* Remove $startDepth elements from the top of the backtrace. */
$bt = array_slice($bt, $startDepth);
return $bt;
}
/* This function converts a SAML2 timestamp on the form
* yyyy-mm-ddThh:mm:ss(\.s+)?Z to a UNIX timestamp. The sub-second
* part is ignored.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment