SwatError
public class SwatError
| Field Summary | |
|---|---|
| protected array | The backtrace of this error. |
| protected static SwatErrorDisplayer | |
| protected string | The file this error occurred in. |
| protected integer | The line this error occurred at. |
| protected static SwatErrorLogger | |
| protected string | The message of this error. |
| protected integer | 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 | 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 | Gets a string representation of this error's severity. |
| string | 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 | 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. |
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()
protected static SwatErrorDisplayer $displayer = null
protected string $file
The file this error occurred in
Set in SwatError::__construct()
protected integer $line
The line this error occurred at
Set in SwatError::__construct()
protected static SwatErrorLogger $logger = null
protected string $message
The message of this error
Set in SwatError::__construct()
protected integer $severity
The severity of this error
Error severity should be one of the E_* constants defined by PHP.
Set in SwatError::__construct()
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.
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.public void display()
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.
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.
name - the name of the parameter.value - the sensitive value of the parameter.protected string formatValue(mixed value)
Formats a parameter value for display in a stack trace
value - the value of the parameter.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.
args - an array of arguments.method - optional. The current method or function.class - optional. The current class name.protected string getSeverityString()
Gets a string representation of this error's severity
public string getSummary()
Gets a one-line short text summary of this error
This summary is useful for log entries and error email titles.
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.
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.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
*\/
?>
method - the method the parameter to which the parameter belongs.name - the name of the parameter.public void log()
Logs this error
The error is logged to the webserver error log.
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.
public static void setDisplayer(SwatErrorDisplayer displayer)
Sets the object that displays SwatError objects when they are processed
For example:
<?php
SwatError::setDisplayer(new SilverorangeDisplayer());
?>
displayer - the object to use to display exceptions.public static void setLogger(SwatErrorLogger logger)
Sets the object that logs SwatError objects when they are processed
For example:
<?php
SwatError::setLogger(new CustomLogger());
?>
logger - the object to use to log exceptions.public static void setupHandler()
Set the PHP error handler to use SwatError
public string toString()
Gets this error as a nicely formatted text block
This is useful for text-based logs and emails.
public string toXHTML()
Gets this error as a nicely formatted XHTML fragment
This is nice for debugging errors on a staging server.
An error in Swat
Unlike
SwatExceptionobjects, 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.