PHP Class Prado\Exceptions\TErrorHandler

TErrorHandler handles all PHP user errors and exceptions generated during servicing user requests. It displays these errors using different templates and if possible, using languages preferred by the client user. Note, PHP parsing errors cannot be caught and handled by TErrorHandler. The templates used to format the error output are stored under System.Exceptions. You may choose to use your own templates, should you not like the templates provided by Prado. Simply set {@link setErrorTemplatePath ErrorTemplatePath} to the path (in namespace format) storing your own templates. There are two sets of templates, one for errors to be displayed to client users (called external errors), one for errors to be displayed to system developers (called internal errors). The template file name for the former is error[StatusCode][-LanguageCode].html, and for the latter it is exception[-LanguageCode].html, where StatusCode refers to response status code (e.g. 404, 500) specified when {@link THttpException} is thrown, and LanguageCode is the client user preferred language code (e.g. en, zh, de). The templates error.html and exception.html are default ones that are used if no other appropriate templates are available. Note, these templates are not Prado control templates. They are simply html files with keywords (e.g. %%ErrorMessage%%, %%Version%%) to be replaced with the corresponding information. By default, TErrorHandler is registered with {@link TApplication} as the error handler module. It can be accessed via {@link TApplication::getErrorHandler()}. You seldom need to deal with the error handler directly. It is mainly used by the application object to handle errors. TErrorHandler may be configured in application configuration file as follows
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends Prado\TModule
Mostrar archivo Open project: pradosoft/prado

Public Methods

Method Description
getErrorTemplatePath ( ) : string
handleError ( $sender, $param ) Handles PHP user errors and exceptions.
init ( $config ) Initializes the module.
setErrorTemplatePath ( $value ) Sets the path storing all error and exception template files.

Protected Methods

Method Description
displayException ( $exception ) Displays exception information.
getErrorTemplate ( $statusCode, $exception ) : string Retrieves the template used for displaying external exceptions.
getExceptionTemplate ( $exception ) : string Retrieves the template used for displaying internal exceptions.
handleExternalError ( $statusCode, $exception ) Displays error to the client user.
handleRecursiveError ( $exception ) Handles error occurs during error handling (called recursive error).
hideSecurityRelated ( string $value, $exception = null ) : string

Private Methods

Method Description
addLink ( $message )
getExactTrace ( $exception )
getPropertyAccessTrace ( $trace, $pattern )
getSourceCode ( $lines, $errorLine )

Method Details

displayException() protected method

Exceptions are displayed with rich context information, including the call stack and the context source code. This method is only invoked when application is in Debug mode.
protected displayException ( $exception )

getErrorTemplate() protected method

External exceptions are those displayed to end-users. They do not contain error source code. Therefore, you might want to override this method to provide your own error template for displaying certain external exceptions. The following tokens in the template will be replaced with corresponding content: %%StatusCode%% : the status code of the exception %%ErrorMessage%% : the error message (HTML encoded). %%ServerAdmin%% : the server admin information (retrieved from Web server configuration) %%Version%% : the version information of the Web server. %%Time%% : the time the exception occurs at
protected getErrorTemplate ( $statusCode, $exception ) : string
return string the template content

getErrorTemplatePath() public method

public getErrorTemplatePath ( ) : string
return string the directory containing error template files.

getExceptionTemplate() protected method

Internal exceptions will be displayed with source code causing the exception. This occurs when the application is in debug mode.
protected getExceptionTemplate ( $exception ) : string
return string the template content

handleError() public method

This is the event handler responding to the Error event raised in {@link TApplication}. The method mainly uses appropriate template to display the error/exception. It terminates the application immediately after the error is displayed.
public handleError ( $sender, $param )

handleExternalError() protected method

THttpException and errors happened when the application is in Debug mode will be displayed to the client user.
protected handleExternalError ( $statusCode, $exception )

handleRecursiveError() protected method

THttpException and errors happened when the application is in Debug mode will be displayed to the client user. Error is displayed without using existing template to prevent further errors.
protected handleRecursiveError ( $exception )

hideSecurityRelated() protected static method

Since: 3.1.6
protected static hideSecurityRelated ( string $value, $exception = null ) : string
$value string
return string

init() public method

This method is required by IModule and is invoked by application.
public init ( $config )

setErrorTemplatePath() public method

The path must be in namespace format, such as System.Exceptions (which is the default).
public setErrorTemplatePath ( $value )