silverorange Code


Swat.SwatException
/Swat/exceptions/SwatException.php at line 44

Class SwatException

Exception
└─SwatException

public class SwatException
extends Exception

An exception in Swat

Exceptions in Swat have handy methods for outputting nicely formed error messages. Call SwatException::setupHandler() to register SwatException as the PHP exception handler. The SwatException handler is able to handle all sub-classes of Exception by internally wrapping non-SwatExceptions in a new instance of a SwatException. This allows all exceptions to be nicely formatted and processed consistently.

Custom displaying and logging of SwatExceptions can be achieved through SwatException::setLogger() and SwatException::setDisplayer().

Filtering Sensitive Data out of Stack Traces:

By default, SwatException displays and logs stack traces that containing all calling information and passed parameters. Sometimes, a methods parameters may contain sensitive data. For exmaple, credit card numbers should not be displayed in stack traces. To filter sensitive data out of stack traces generated by SwatException, add the following documentation tag to the method-level documentation:

<?php
/**
 * @sensitive $parameter_name
 
?>

Any parameter having the @sensitive tag in its method-level documentation will be filtered out of stack traces. IMPORATNT: Each tag can only filter one parameter. Use multiple @sensitive documentation tags to filter multiple parameters in a single method.

Copyright:
2004-2007 silverorange
License:
http://www.gnu.org/copyleft/lesser.html LGPL License 2.1

Field Summary
protected mixed

$backtrace

protected mixed

$class

protected static SwatExceptionDisplayer

$displayer

protected static SwatExceptionLogger

$logger

Constructor Summary

SwatException(mixed message, mixed code)

Method Summary
void

display()

Displays this exception.

protected void

displayStyleSheet()

Displays style sheet required for XHMTL exception formatting.

protected string

formatSensitiveParam(string name, mixed value)

Removes sensitive information from a parameter value and formats the parameter as a string.

protected string

formatValue(mixed value)

Formats a parameter value for display in a stack trace.

protected string

getArguments(array args, string function, string class)

Formats a method call's arguments.

string

getClass()

Gets the name of the class this exception represents.

string

getSummary()

Gets a one-line short text summary of this exception.

static void

handle(Exception e)

Handles an exception.

protected boolean

isSensitiveParameter(ReflectionFunctionAbstract method, string name)

Detects whether or not a parameter is sensitive from the method-level documentation of the parameter's method.

void

log()

Logs this exception.

void

process(boolean exit, boolean handled)

Processes this exception.

static void

setDisplayer(SwatExceptionDisplayer displayer)

Sets the object that displays SwatException objects when they are processed.

static void

setLogger(SwatExceptionLogger logger)

Sets the object that logs SwatException objects when they are processed.

static void

setupHandler(string class)

Set the PHP exception handler to use SwatException.

string

toString()

Gets this exception as a nicely formatted text block.

string

toXHTML()

Gets this exception as a nicely formatted XHTML fragment.

boolean

wasHandled()

Gets whether or not this exception was manually handled.

Field Detail

/Swat/exceptions/SwatException.php at line 48

backtrace

protected mixed $backtrace = null

/Swat/exceptions/SwatException.php at line 49

class

protected mixed $class = null

/Swat/exceptions/SwatException.php at line 54

displayer

protected static SwatExceptionDisplayer $displayer = null


/Swat/exceptions/SwatException.php at line 59

logger

protected static SwatExceptionLogger $logger = null


Constructor Detail

/Swat/exceptions/SwatException.php at line 126

SwatException

public SwatException(mixed message, mixed code)

Method Detail

/Swat/exceptions/SwatException.php at line 203

display

public void display()

Displays this exception

This exception is displayed as either text or XHMTL depending on the current execution context. If there is a request URI, this exception is displayed as XHTML. Otherwise, this exception is displayed as text.


/Swat/exceptions/SwatException.php at line 559

displayStyleSheet

protected void displayStyleSheet()

Displays style sheet required for XHMTL exception formatting

This is purposly not in a separate file so that even if this exception causes problems including other files the exception styles will be displayed.


/Swat/exceptions/SwatException.php at line 484

formatSensitiveParam

protected string formatSensitiveParam(string name, mixed value)

Removes sensitive information from a parameter value and formats the parameter as a string

This is used, for example, to filter credit/debit card numbers from stack traces. By default, a string of the form "[$name FILTERED]" is returned.

Parameters:
name - the name of the parameter.
value - the sensitive value of the parameter.
Returns:
the filtered formatted version of the parameter.
See Also:
SwatException::$sensitive_param_names

/Swat/exceptions/SwatException.php at line 499

formatValue

protected string formatValue(mixed value)

Formats a parameter value for display in a stack trace

Parameters:
value - the value of the parameter.
Returns:
the formatted version of the parameter.

/Swat/exceptions/SwatException.php at line 425

getArguments

protected string getArguments(array args, string function, string class)

Formats a method call's arguments

This method is also responsible for filtering sensitive parameters out of the final stack trace.

Parameters:
args - an array of arguments.
function - optional. The current method or function.
class - optional. The current class name.
Returns:
the arguments formatted into a comma delimited string.

/Swat/exceptions/SwatException.php at line 371

getClass

public string getClass()

Gets the name of the class this exception represents

This is usually, but not always, equivalent to get_class($this).

Returns:
the name of the class this exception represents.

/Swat/exceptions/SwatException.php at line 229

getSummary

public string getSummary()

Gets a one-line short text summary of this exception

This summary is useful for log entries and error email titles.

Returns:
a one-line summary of this exception

/Swat/exceptions/SwatException.php at line 401

handle

public static void handle(Exception e)

Handles an exception

Wraps a generic exception in a SwatException object and process the SwatException object.

Parameters:
e - the exception to handle.

/Swat/exceptions/SwatException.php at line 606

isSensitiveParameter

protected boolean isSensitiveParameter(ReflectionFunctionAbstract method, string name)

Detects whether or not a parameter is sensitive from the method-level documentation of the parameter's method

Parameters with the following docblock tag are considered sensitive:

<?php
/**
 * @sensitive $parameter_name
 
?>

Parameters:
method - the method the parameter to which the parameter belongs.
name - the name of the parameter.
Returns:
true if the parameter is sensitive and false if the method is not sensitive.

/Swat/exceptions/SwatException.php at line 183

log

public void log()

Logs this exception

The exception is logged to the webserver error log.


/Swat/exceptions/SwatException.php at line 161

process

public void process(boolean exit, boolean handled)

Processes this exception

Processing involves displaying errors, logging errors and sending error message emails

Parameters:
exit - optional. Whether or not to exit after processing this exception. If unspecified, defaults to true.
handled - optional. Whether or not this exception was manually handled. If unspecified defaults to true. Usually this parameter should be true if you catch an exception and manually call process on the exception.

/Swat/exceptions/SwatException.php at line 104

setDisplayer

public static void setDisplayer(SwatExceptionDisplayer displayer)

Sets the object that displays SwatException objects when they are processed

For example:

<?php
SwatException
::setDisplayer(new SilverorangeDisplayer());
?>

Parameters:
displayer - the object to use to display exceptions.

/Swat/exceptions/SwatException.php at line 84

setLogger

public static void setLogger(SwatExceptionLogger logger)

Sets the object that logs SwatException objects when they are processed

For example:

<?php
SwatException
::setLogger(new CustomLogger());
?>

Parameters:
logger - the object to use to log exceptions.

/Swat/exceptions/SwatException.php at line 118

setupHandler

public static void setupHandler(string class)

Set the PHP exception handler to use SwatException

Parameters:
class - the exception class containing a static handle() method.

/Swat/exceptions/SwatException.php at line 254

toString

public string toString()

Gets this exception as a nicely formatted text block

This is useful for text-based logs and emails.

Returns:
this exception formatted as text.

/Swat/exceptions/SwatException.php at line 308

toXHTML

public string toXHTML()

Gets this exception as a nicely formatted XHTML fragment

This is nice for debugging errors on a staging server.

Returns:
this exception formatted as XHTML.

/Swat/exceptions/SwatException.php at line 385

wasHandled

public boolean wasHandled()

Gets whether or not this exception was manually handled

Returns:
true if this exception wa smanually handled and false if it was not.

silverorange Code