silverorange Code


Swat.SwatError
/Swat/SwatError.php at line 23

Class SwatError

SwatError

public class SwatError

An error in Swat

Unlike SwatException objects, errors do not interrupt the flow of execution and can not be caught. Errors in Swat have handy methods for outputting nicely formed error messages and logging errors.

Like SwatException, SwatError filters sensitive data from stack trace parameters. See the class-level documentation of SwatException for details on how this works.

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

Field Summary
protected array

$backtrace

The backtrace of this error.

protected static SwatErrorDisplayer

$displayer

protected string

$file

The file this error occurred in.

protected integer

$line

The line this error occurred at.

protected static SwatErrorLogger

$logger

protected string

$message

The message of this error.

protected integer

$severity

The severity of this error.

Constructor Summary

SwatError(integer severity, string message, string file, integer line)

Creates a new error object.

Method Summary
void

display()

protected void

displayStyleSheet()

Displays styles required to show XHTML error messages.

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, mixed function, string class, string method)

Formats a method call's arguments.

protected string

getSeverityString()

Gets a string representation of this error's severity.

string

getSummary()

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

static void

handle(integer errno, string errstr, string errfile, integer errline)

Handles an error.

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 error.

void

process()

Processes this error.

static void

setDisplayer(SwatErrorDisplayer displayer)

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

static void

setLogger(SwatErrorLogger logger)

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

static void

setupHandler()

Set the PHP error handler to use SwatError.

string

toString()

Gets this error as a nicely formatted text block.

string

toXHTML()

Gets this error as a nicely formatted XHTML fragment.

Field Detail

/Swat/SwatError.php at line 74

backtrace

protected array $backtrace

The backtrace of this error

This should be an array of the form provided by the built-in PHP function debug_backtrace().

Set in SwatError::__construct()


/Swat/SwatError.php at line 79

displayer

protected static SwatErrorDisplayer $displayer = null


/Swat/SwatError.php at line 53

file

protected string $file

The file this error occurred in

Set in SwatError::__construct()


/Swat/SwatError.php at line 62

line

protected integer $line

The line this error occurred at

Set in SwatError::__construct()


/Swat/SwatError.php at line 84

logger

protected static SwatErrorLogger $logger = null


/Swat/SwatError.php at line 34

message

protected string $message

The message of this error

Set in SwatError::__construct()


/Swat/SwatError.php at line 44

severity

protected integer $severity

The severity of this error

Error severity should be one of the E_* constants defined by PHP. Set in SwatError::__construct()


Constructor Detail

/Swat/SwatError.php at line 142

SwatError

public SwatError(integer severity, string message, string file, integer line)

Creates a new error object

Error objects contain methods to display and log all types of errors that may occur.

Parameters:
severity - the error code of this error. This should be one of the E_* constants set by PHP. See {@link http://php.net/manual/en/ref.errorfunc.php Error Handling and Logging Functions}.
message - the error message of this error.
file - the name of the file this error occurred in.
line - the line number this error occurred at.

Method Detail

/Swat/SwatError.php at line 201

display

public void display()

/Swat/SwatError.php at line 523

displayStyleSheet

protected void displayStyleSheet()

Displays styles required to show XHTML error messages

The styles are only output once even if multiple errors are displayed during one request.


/Swat/SwatError.php at line 449

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/SwatError.php at line 464

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/SwatError.php at line 390

getArguments

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

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.
method - optional. The current method or function.
class - optional. The current class name.
Returns:
the arguments formatted into a comma delimited string.

/Swat/SwatError.php at line 556

getSeverityString

protected string getSeverityString()

Gets a string representation of this error's severity

Returns:
a string representation of this error's severity.

/Swat/SwatError.php at line 224

getSummary

public string getSummary()

Gets a one-line short text summary of this error

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

Returns:
a one-line summary of this error.

/Swat/SwatError.php at line 366

handle

public static void handle(integer errno, string errstr, string errfile, integer errline)

Handles an error

When an error occurs, a SwatError object is created and processed.

Parameters:
errno - the severity code of the handled error.
errstr - the message of the handled error.
errfile - the file ther handled error occurred in.
errline - the line the handled error occurred at.

/Swat/SwatError.php at line 597

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/SwatError.php at line 188

log

public void log()

Logs this error

The error is logged to the webserver error log.


/Swat/SwatError.php at line 168

process

public void process()

Processes this error

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

If a fatal error has occured, this calls exit to ensure no further processing is done.


/Swat/SwatError.php at line 119

setDisplayer

public static void setDisplayer(SwatErrorDisplayer displayer)

Sets the object that displays SwatError objects when they are processed

For example:

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

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

/Swat/SwatError.php at line 99

setLogger

public static void setLogger(SwatErrorLogger logger)

Sets the object that logs SwatError objects when they are processed

For example:

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

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

/Swat/SwatError.php at line 626

setupHandler

public static void setupHandler()

Set the PHP error handler to use SwatError


/Swat/SwatError.php at line 246

toString

public string toString()

Gets this error as a nicely formatted text block

This is useful for text-based logs and emails.

Returns:
this error formatted as text.

/Swat/SwatError.php at line 300

toXHTML

public string toXHTML()

Gets this error as a nicely formatted XHTML fragment

This is nice for debugging errors on a staging server.

Returns:
this error formatted as XHTML.

silverorange Code