PHP Class lithium\core\ErrorHandler

{{{ embed:lithium\tests\cases\core\ErrorHandlerTest::testExceptionCatching(2-7) }}} Using a series of cascading rules and handlers, it is possible to capture and handle very specific errors and exceptions.
Inheritance: extends StaticObject
Show file Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Property Type Description
$_checks Default checks are for code, stack and message.
$_config Configuration parameters.
$_exceptionHandler Currently registered exception handler.
$_isRunning State of error/exception handling.
$_runOptions

Public Methods

Method Description
apply ( $object, array $conditions, $handler )
config ( array $config = [] ) : Current Configure the ErrorHandler.
handle ( object | array $info, array $scope = [] ) : boolean Receives the handled errors and exceptions that have been caught, and processes them in a normalized manner.
isRunning ( ) Returns the state of the ErrorHandler, indicating whether or not custom error/exception handers have been regsitered.
matches ( $info, $conditions )
reset ( ) Setup basic error handling checks/types, as well as register the error and exception handlers and wipes out all configuration and resets the error handler to its initial state when loaded. Mainly used for testing.
run ( array $config = [] ) Register error and exception handlers.
stop ( ) Unooks ErrorHandler's exception and error handlers, and restores PHP's defaults. May have unexpected results if it is not matched with a prior call to run(), or if other error handlers are set after a call to run().
trace ( array $stack ) : array Trim down a typical stack trace to class & method calls.

Protected Methods

Method Description
_origin ( array $stack ) : string Determine frame from the stack trace where the error/exception was first generated.

Method Details

_origin() protected static method

Determine frame from the stack trace where the error/exception was first generated.
protected static _origin ( array $stack ) : string
$stack array Stack trace from error/exception that was produced.
return string Class where error/exception was generated.

apply() public static method

public static apply ( $object, array $conditions, $handler )
$conditions array

config() public static method

Configure the ErrorHandler.
public static config ( array $config = [] ) : Current
$config array Configuration directives.
return Current configuration set.

handle() public static method

Receives the handled errors and exceptions that have been caught, and processes them in a normalized manner.
public static handle ( object | array $info, array $scope = [] ) : boolean
$info object | array
$scope array
return boolean True if successfully handled, false otherwise.

isRunning() public static method

Returns the state of the ErrorHandler, indicating whether or not custom error/exception handers have been regsitered.
public static isRunning ( )

matches() public static method

public static matches ( $info, $conditions )

reset() public static method

Setup basic error handling checks/types, as well as register the error and exception handlers and wipes out all configuration and resets the error handler to its initial state when loaded. Mainly used for testing.
public static reset ( )

run() public static method

This method (ErrorHandler::run()) needs to be called as early as possible in the bootstrap cycle; immediately after require-ing bootstrap/libraries.php is your best bet.
public static run ( array $config = [] )
$config array The configuration with which to start the error handler. Available options include: - `'trapErrors'` _boolean_: Defaults to `false`. If set to `true`, PHP errors will be caught by `ErrorHandler` and handled in-place. Execution will resume in the same context in which the error occurred. - `'convertErrors'` _boolean_: Defaults to `true`, and specifies that all PHP errors should be converted to `ErrorException`s and thrown from the point where the error occurred. The exception will be caught at the first point in the stack trace inside a matching `try`/`catch` block, or that has a matching error handler applied using the `apply()` method.

stop() public static method

Unooks ErrorHandler's exception and error handlers, and restores PHP's defaults. May have unexpected results if it is not matched with a prior call to run(), or if other error handlers are set after a call to run().
public static stop ( )

trace() public static method

Trim down a typical stack trace to class & method calls.
public static trace ( array $stack ) : array
$stack array A `debug_backtrace()`-compatible stack trace output.
return array Returns a flat stack array containing class and method references.

Property Details

$_checks protected static property

Default checks are for code, stack and message.
protected static $_checks

$_config protected static property

Configuration parameters.
protected static $_config

$_exceptionHandler protected static property

Currently registered exception handler.
protected static $_exceptionHandler

$_isRunning protected static property

State of error/exception handling.
protected static $_isRunning

$_runOptions protected static property

protected static $_runOptions