PHP Class yii\web\ErrorHandler

ErrorHandler displays these errors using appropriate views based on the nature of the errors and the mode the application runs at. ErrorHandler is configured as an application component in Application by default. You can access that instance via Yii::$app->errorHandler. For more details and usage information on ErrorHandler, see the guide article on handling errors.
Since: 2.0
Author: Qiang Xue ([email protected])
Author: Timur Ruziev ([email protected])
Inheritance: extends yii\base\ErrorHandler
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$callStackItemView the path of the view file for rendering exceptions and errors call stack element.
$displayVars list of the PHP predefined variables that should be displayed on the error page. Note that a variable must be accessible via $GLOBALS. Otherwise it won't be displayed. Defaults to ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION'].
$errorAction the route (e.g. site/error) to the controller action that will be used to display external errors. Inside the action, it can retrieve the error information using Yii::$app->errorHandler->exception. This property defaults to null, meaning ErrorHandler will handle the error display.
$errorView the path of the view file for rendering exceptions without call stack information.
$exceptionView the path of the view file for rendering exceptions.
$maxSourceLines maximum number of source code lines to be displayed. Defaults to 19.
$maxTraceSourceLines maximum number of trace source code lines to be displayed. Defaults to 13.
$previousExceptionView the path of the view file for rendering previous exceptions.

Public Methods

Method Description
addTypeLinks ( string $code ) : string Adds informational links to the given PHP type/class.
argumentsToString ( array $args ) : string Converts arguments array to its string representation
createFrameworkVersionLink ( ) : string Creates string containing HTML link which refers to the page with the current version of the framework and version number text.
createHttpStatusLink ( integer $statusCode, string $statusDescription ) : string Creates HTML containing link to the page with the information on given HTTP status code.
createServerInformationLink ( ) : string Creates string containing HTML link which refers to the home page of determined web-server software and its full name.
getExceptionName ( Exception $exception ) : string Returns human-readable exception name
htmlEncode ( string $text ) : string Converts special characters to HTML entities.
isCoreFile ( string $file ) : boolean Determines whether given name of the file belongs to the framework.
renderCallStackItem ( string | null $file, integer | null $line, string | null $class, string | null $method, array $args, integer $index ) : string Renders a single call stack element.
renderFile ( string $_file_, array $_params_ ) : string Renders a view file as a PHP script.
renderPreviousExceptions ( Exception $exception ) : string Renders the previous exception stack for a given Exception.
renderRequest ( ) : string Renders the global variables of the request.

Protected Methods

Method Description
convertExceptionToArray ( Exception $exception ) : array Converts an exception into an array.
getTypeUrl ( string $class, string | null $method ) : string | null Returns the informational link URL for a given PHP type/class.
renderException ( Exception $exception ) Renders the exception.

Method Details

argumentsToString() public method

Converts arguments array to its string representation
public argumentsToString ( array $args ) : string
$args array arguments array to be converted
return string string representation of the arguments array

convertExceptionToArray() protected method

Converts an exception into an array.
protected convertExceptionToArray ( Exception $exception ) : array
$exception Exception the exception being converted
return array the array representation of the exception.

getExceptionName() public method

Returns human-readable exception name
public getExceptionName ( Exception $exception ) : string
$exception Exception
return string human-readable exception name or null if it cannot be determined

getTypeUrl() protected method

Returns the informational link URL for a given PHP type/class.
See also: addTypeLinks()
protected getTypeUrl ( string $class, string | null $method ) : string | null
$class string the type or class name.
$method string | null the method name.
return string | null the informational link URL.

htmlEncode() public method

Converts special characters to HTML entities.
public htmlEncode ( string $text ) : string
$text string to encode.
return string encoded original text.

isCoreFile() public method

Determines whether given name of the file belongs to the framework.
public isCoreFile ( string $file ) : boolean
$file string name to be checked.
return boolean whether given name of the file belongs to the framework.

renderCallStackItem() public method

Renders a single call stack element.
public renderCallStackItem ( string | null $file, integer | null $line, string | null $class, string | null $method, array $args, integer $index ) : string
$file string | null name where call has happened.
$line integer | null number on which call has happened.
$class string | null called class name.
$method string | null called function/method name.
$args array array of method arguments.
$index integer number of the call stack element.
return string HTML content of the rendered call stack element.

renderException() protected method

Renders the exception.
protected renderException ( Exception $exception )
$exception Exception the exception to be rendered.

renderFile() public method

Renders a view file as a PHP script.
public renderFile ( string $_file_, array $_params_ ) : string
$_file_ string the view file.
$_params_ array the parameters (name-value pairs) that will be extracted and made available in the view file.
return string the rendering result

renderPreviousExceptions() public method

Renders the previous exception stack for a given Exception.
public renderPreviousExceptions ( Exception $exception ) : string
$exception Exception the exception whose precursors should be rendered.
return string HTML content of the rendered previous exceptions. Empty string if there are none.

renderRequest() public method

List of global variables is defined in [[displayVars]].
See also: displayVars
public renderRequest ( ) : string
return string the rendering result

Property Details

$callStackItemView public property

the path of the view file for rendering exceptions and errors call stack element.
public $callStackItemView

$displayVars public property

list of the PHP predefined variables that should be displayed on the error page. Note that a variable must be accessible via $GLOBALS. Otherwise it won't be displayed. Defaults to ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION'].
See also: renderRequest()
Since: 2.0.7
public $displayVars

$errorAction public property

the route (e.g. site/error) to the controller action that will be used to display external errors. Inside the action, it can retrieve the error information using Yii::$app->errorHandler->exception. This property defaults to null, meaning ErrorHandler will handle the error display.
public $errorAction

$errorView public property

the path of the view file for rendering exceptions without call stack information.
public $errorView

$exceptionView public property

the path of the view file for rendering exceptions.
public $exceptionView

$maxSourceLines public property

maximum number of source code lines to be displayed. Defaults to 19.
public $maxSourceLines

$maxTraceSourceLines public property

maximum number of trace source code lines to be displayed. Defaults to 13.
public $maxTraceSourceLines

$previousExceptionView public property

the path of the view file for rendering previous exceptions.
public $previousExceptionView