ignaszak/exception

该软件包已被废弃,不再维护。作者建议使用ignaszak/error-handler软件包。

异常处理程序

v1.1.2 2016-02-03 19:42 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:52:21 UTC


README

Build Status Coverage Status

此软件包提供错误处理程序接口

Screnshot

安装

该软件包可通过Composer/Packagist获取,因此只需将以下行添加到您的composer.json文件中

"require" : {
    "ignaszak/exception" : "*"
}

或者

php composer.phar require ignaszak/exception

运行测试

只需在工作目录中运行phpunit

php phpunit.phar

要求

php >= 7.0

示例

include __DIR__ . '/autoload.php';

$exception = new Ignaszak\Exception\Start;

// Set which PHP errors are reported
$exception->errorReporting = E_ALL;

// Set display mode if error occured:
//    'dev'      - full developer error interface
//    'user'     - simple message for users
//    'location' - redirect to oder site with custom error message
//    'none'     - set no display
$exception->display = 'dev';

// Set which PHP errors are displayed in 'user' or 'location' mode
$exception->userReporting = E_ALL & ~E_NOTICE;

// Set message for 'user' mode
$exception->userMessage = 'Error occured.';

// Set location adress for 'location' mode
$exception->userLocation = 'http://example.com';

// Create log file if error occured
$exception->createLogFile = true;

// Log files dir
$exception->logFileDir = __DIR__ . '/logs';

$exception->run();

// Make some errors
notice;

class Test {
    public function throwException()
    {
        throw new Exception('Test exception');
    }
}

try {
    (new Test)->throwException();
} catch (Exception $e) {
    $exception->catchException($e);
}

fatalError();