ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML_Error_Exception Class Reference
+ Inheritance diagram for SimpleSAML_Error_Exception:
+ Collaboration diagram for SimpleSAML_Error_Exception:

Public Member Functions

 __construct ($message, $code=0, Exception $cause=null)
 Constructor for this error. More...
 
 getBacktrace ()
 Retrieve the backtrace. More...
 
 getCause ()
 Retrieve the cause of this exception. More...
 
 getClass ()
 Retrieve the class of this exception. More...
 
 format ($anonymize=false)
 Format this exception for logging. More...
 
 formatBacktrace ($anonymize=false)
 Format the backtrace for logging. More...
 
 log ($default_level)
 Print the exception to the log, by default with log level error. More...
 
 logError ()
 Print the exception to the log with log level error. More...
 
 logWarning ()
 Print the exception to the log with log level warning. More...
 
 logInfo ()
 Print the exception to the log with log level info. More...
 
 logDebug ()
 Print the exception to the log with log level debug. More...
 
 __sleep ()
 Function for serialization. More...
 

Static Public Member Functions

static fromException (Exception $e)
 Convert any exception into a SimpleSAML_Error_Exception. More...
 

Protected Member Functions

 initBacktrace (Exception $exception)
 Load the backtrace from the given exception. More...
 
 logBacktrace ($level=\SimpleSAML\Logger::DEBUG)
 Print the backtrace to the log if the 'debug' option is enabled in the configuration. More...
 

Private Attributes

 $backtrace
 
 $cause
 

Detailed Description

Definition at line 12 of file Exception.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML_Error_Exception::__construct (   $message,
  $code = 0,
Exception  $cause = null 
)

Constructor for this error.

Note that the cause will be converted to a SimpleSAML_Error_UnserializableException unless it is a subclass of SimpleSAML_Error_Exception.

Parameters
string$messageException message
int$codeError code
Exception | null$causeThe cause of this exception.

Definition at line 44 of file Exception.php.

References $cause, $code, $message, fromException(), and initBacktrace().

45  {
46  assert(is_string($message));
47  assert(is_int($code));
48 
49  parent::__construct($message, $code);
50 
51  $this->initBacktrace($this);
52 
53  if ($cause !== null) {
55  }
56  }
$code
Definition: example_050.php:99
initBacktrace(Exception $exception)
Load the backtrace from the given exception.
Definition: Exception.php:81
catch(Exception $e) $message
static fromException(Exception $e)
Convert any exception into a SimpleSAML_Error_Exception.
Definition: Exception.php:66
+ Here is the call graph for this function:

Member Function Documentation

◆ __sleep()

SimpleSAML_Error_Exception::__sleep ( )

Function for serialization.

This function builds a list of all variables which should be serialized. It will serialize all variables except the Exception::trace variable.

Returns
array Array with the variables that should be serialized.

Definition at line 303 of file Exception.php.

References $i, and $ret.

304  {
305 
306  $ret = array_keys((array) $this);
307 
308  foreach ($ret as $i => $e) {
309  if ($e === "\0Exception\0trace") {
310  unset($ret[$i]);
311  }
312  }
313 
314  return $ret;
315  }
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19

◆ format()

SimpleSAML_Error_Exception::format (   $anonymize = false)

Format this exception for logging.

Create an array of lines for logging.

Parameters
boolean$anonymizeWhether the resulting messages should be anonymized or not.
Returns
array Log lines that should be written out.

Definition at line 150 of file Exception.php.

References $ret, formatBacktrace(), and getClass().

Referenced by SimpleSAML_Error_Error\saveError().

151  {
152  $ret = array(
153  $this->getClass().': '.$this->getMessage(),
154  );
155  return array_merge($ret, $this->formatBacktrace($anonymize));
156  }
$ret
Definition: parser.php:6
getClass()
Retrieve the class of this exception.
Definition: Exception.php:135
formatBacktrace($anonymize=false)
Format the backtrace for logging.
Definition: Exception.php:168
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatBacktrace()

SimpleSAML_Error_Exception::formatBacktrace (   $anonymize = false)

Format the backtrace for logging.

Create an array of lines for logging from the backtrace.

Parameters
boolean$anonymizeWhether the resulting messages should be anonymized or not.
Returns
array All lines of the backtrace, properly formatted.

Definition at line 168 of file Exception.php.

References $i, $ret, and SimpleSAML_Configuration\getInstance().

Referenced by format(), and logBacktrace().

169  {
170  $ret = array();
171  $basedir = SimpleSAML_Configuration::getInstance()->getBaseDir();
172 
173  $e = $this;
174  do {
175  if ($e !== $this) {
176  $ret[] = 'Caused by: '.$e->getClass().': '.$e->getMessage();
177  }
178  $ret[] = 'Backtrace:';
179 
180  $depth = count($e->backtrace);
181  foreach ($e->backtrace as $i => $trace) {
182  if ($anonymize) {
183  $trace = str_replace($basedir, '', $trace);
184  }
185 
186  $ret[] = ($depth - $i - 1).' '.$trace;
187  }
188  $e = $e->cause;
189  } while ($e !== null);
190 
191  return $ret;
192  }
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromException()

static SimpleSAML_Error_Exception::fromException ( Exception  $e)
static

Convert any exception into a SimpleSAML_Error_Exception.

Parameters
Exception$eThe exception.
Returns
SimpleSAML_Error_Exception The new exception.

Definition at line 66 of file Exception.php.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getBacktrace()

SimpleSAML_Error_Exception::getBacktrace ( )

Retrieve the backtrace.

Returns
array An array where each function call is a single item.

Definition at line 113 of file Exception.php.

References $backtrace.

114  {
115  return $this->backtrace;
116  }

◆ getCause()

SimpleSAML_Error_Exception::getCause ( )

Retrieve the cause of this exception.

Returns
SimpleSAML_Error_Exception|null The cause of this exception.

Definition at line 124 of file Exception.php.

References $cause.

125  {
126  return $this->cause;
127  }

◆ getClass()

SimpleSAML_Error_Exception::getClass ( )

Retrieve the class of this exception.

Returns
string The name of the class.

Definition at line 135 of file Exception.php.

Referenced by SimpleSAML_Error_NotFound\format(), format(), logDebug(), logError(), logInfo(), and logWarning().

136  {
137  return get_class($this);
138  }
+ Here is the caller graph for this function:

◆ initBacktrace()

SimpleSAML_Error_Exception::initBacktrace ( Exception  $exception)
protected

Load the backtrace from the given exception.

Parameters
Exception$exceptionThe exception we should fetch the backtrace from.

Definition at line 81 of file Exception.php.

References $t.

Referenced by SimpleSAML_Error_UnserializableException\__construct(), and __construct().

82  {
83 
84  $this->backtrace = array();
85 
86  // position in the top function on the stack
87  $pos = $exception->getFile().':'.$exception->getLine();
88 
89  foreach ($exception->getTrace() as $t) {
90  $function = $t['function'];
91  if (array_key_exists('class', $t)) {
92  $function = $t['class'].'::'.$function;
93  }
94 
95  $this->backtrace[] = $pos.' ('.$function.')';
96 
97  if (array_key_exists('file', $t)) {
98  $pos = $t['file'].':'.$t['line'];
99  } else {
100  $pos = '[builtin]';
101  }
102  }
103 
104  $this->backtrace[] = $pos.' (N/A)';
105  }
+ Here is the caller graph for this function:

◆ log()

SimpleSAML_Error_Exception::log (   $default_level)

Print the exception to the log, by default with log level error.

Override to allow errors extending this class to specify the log level themselves.

Parameters
int$default_levelThe log level to use if this method was not overridden.

Definition at line 235 of file Exception.php.

References DEBUG.

Referenced by sspmod_saml_IdP_SAML2\handleAuthError().

236  {
237  $fn = array(
238  SimpleSAML\Logger::ERR => 'logError',
239  SimpleSAML\Logger::WARNING => 'logWarning',
240  SimpleSAML\Logger::INFO => 'logInfo',
241  SimpleSAML\Logger::DEBUG => 'logDebug',
242  );
243  call_user_func(array($this, $fn[$default_level]), $default_level);
244  }
const DEBUG
Attribute-related utility methods.
+ Here is the caller graph for this function:

◆ logBacktrace()

SimpleSAML_Error_Exception::logBacktrace (   $level = \SimpleSAML\Logger::DEBUG)
protected

Print the backtrace to the log if the 'debug' option is enabled in the configuration.

Definition at line 198 of file Exception.php.

References $backtrace, Sabre\VObject\$debug, formatBacktrace(), and SimpleSAML_Configuration\getInstance().

Referenced by logDebug(), logError(), logInfo(), and logWarning().

199  {
200  // see if debugging is enabled for backtraces
201  $debug = SimpleSAML_Configuration::getInstance()->getArrayize('debug', array('backtraces' => false));
202 
203  if (!(in_array('backtraces', $debug, true) // implicitly enabled
204  || (array_key_exists('backtraces', $debug) && $debug['backtraces'] === true) // explicitly set
205  // TODO: deprecate the old style and remove it in 2.0
206  || (array_key_exists(0, $debug) && $debug[0] === true) // old style 'debug' configuration option
207  )) {
208  return;
209  }
210 
211  $backtrace = $this->formatBacktrace();
212 
213  $callback = array('\SimpleSAML\Logger');
214  $functions = array(
215  \SimpleSAML\Logger::ERR => 'error',
216  \SimpleSAML\Logger::WARNING => 'warning',
217  \SimpleSAML\Logger::INFO => 'info',
218  \SimpleSAML\Logger::DEBUG => 'debug',
219  );
220  $callback[] = $functions[$level];
221 
222  foreach ($backtrace as $line) {
223  call_user_func($callback, $line);
224  }
225  }
const DEBUG
Attribute-related utility methods.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
formatBacktrace($anonymize=false)
Format the backtrace for logging.
Definition: Exception.php:168
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logDebug()

SimpleSAML_Error_Exception::logDebug ( )

Print the exception to the log with log level debug.

This function will write this exception to the log, including a full backtrace.

Definition at line 288 of file Exception.php.

References DEBUG, SimpleSAML\Logger\debug(), getClass(), and logBacktrace().

289  {
290  SimpleSAML\Logger::debug($this->getClass().': '.$this->getMessage());
292  }
static debug($string)
Definition: Logger.php:211
logBacktrace($level=\SimpleSAML\Logger::DEBUG)
Print the backtrace to the log if the 'debug' option is enabled in the configuration.
Definition: Exception.php:198
const DEBUG
Attribute-related utility methods.
getClass()
Retrieve the class of this exception.
Definition: Exception.php:135
+ Here is the call graph for this function:

◆ logError()

SimpleSAML_Error_Exception::logError ( )

Print the exception to the log with log level error.

This function will write this exception to the log, including a full backtrace.

Definition at line 252 of file Exception.php.

References SimpleSAML\Logger\error(), getClass(), and logBacktrace().

Referenced by SimpleSAML_Error_Error\show().

253  {
254  SimpleSAML\Logger::error($this->getClass().': '.$this->getMessage());
255  $this->logBacktrace(\SimpleSAML\Logger::ERR);
256  }
logBacktrace($level=\SimpleSAML\Logger::DEBUG)
Print the backtrace to the log if the 'debug' option is enabled in the configuration.
Definition: Exception.php:198
Attribute-related utility methods.
static error($string)
Definition: Logger.php:166
getClass()
Retrieve the class of this exception.
Definition: Exception.php:135
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logInfo()

SimpleSAML_Error_Exception::logInfo ( )

Print the exception to the log with log level info.

This function will write this exception to the log, including a full backtrace.

Definition at line 276 of file Exception.php.

References getClass(), SimpleSAML\Logger\info(), and logBacktrace().

277  {
278  SimpleSAML\Logger::info($this->getClass().': '.$this->getMessage());
279  $this->logBacktrace(\SimpleSAML\Logger::INFO);
280  }
logBacktrace($level=\SimpleSAML\Logger::DEBUG)
Print the backtrace to the log if the 'debug' option is enabled in the configuration.
Definition: Exception.php:198
Attribute-related utility methods.
static info($string)
Definition: Logger.php:199
getClass()
Retrieve the class of this exception.
Definition: Exception.php:135
+ Here is the call graph for this function:

◆ logWarning()

SimpleSAML_Error_Exception::logWarning ( )

Print the exception to the log with log level warning.

This function will write this exception to the log, including a full backtrace.

Definition at line 264 of file Exception.php.

References getClass(), logBacktrace(), and SimpleSAML\Logger\warning().

265  {
266  SimpleSAML\Logger::warning($this->getClass().': '.$this->getMessage());
267  $this->logBacktrace(\SimpleSAML\Logger::WARNING);
268  }
logBacktrace($level=\SimpleSAML\Logger::DEBUG)
Print the backtrace to the log if the 'debug' option is enabled in the configuration.
Definition: Exception.php:198
Attribute-related utility methods.
static warning($string)
Definition: Logger.php:177
getClass()
Retrieve the class of this exception.
Definition: Exception.php:135
+ Here is the call graph for this function:

Field Documentation

◆ $backtrace

SimpleSAML_Error_Exception::$backtrace
private

Definition at line 23 of file Exception.php.

Referenced by getBacktrace(), and logBacktrace().

◆ $cause


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