josantonius / errorhandler
1.1.8
2018-01-16 02:06 UTC
Requires
- php: ^5.6 || ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3 || ^2.8
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^5.7 || ^6.0
- squizlabs/php_codesniffer: ^3.0
README
PHP 库,用于处理异常和错误。
需求
此库支持 PHP 版本 5.6 或更高版本,并兼容 HHVM 版本 3.0 或更高版本。
安装
安装此扩展的首选方式是通过 Composer。
要安装 PHP ErrorHandler 库,只需
$ composer require Josantonius/ErrorHandler
上一个命令将仅安装必要的文件,如果您想 下载整个源代码,可以使用
$ composer require Josantonius/ErrorHandler --prefer-source
您也可以使用 Git 克隆整个仓库
$ git clone https://github.com/Josantonius/PHP-ErrorHandler.git
或 手动安装
$ wget https://raw.githubusercontent.com/Josantonius/PHP-ErrorHandler/master/src/ErrorHandler.php
可用方法
此库中的可用方法
- 设置自定义方法以渲染
ErrorHandler::setCustomMethod($class, $method, $repeat, $default);
属性 | 描述 | 类型 | 必需 | 默认值 |
---|---|---|---|---|
$class | 类名或类对象。 | callable | 是 | |
$method | 方法名。 | string | 是 | |
$repeat | 重复方法的次数。 | int | 否 | 0 |
$default | 显示默认视图。 | boolean | 否 | false |
返回 (void)
快速开始
要使用此类与 Composer
require __DIR__ . '/vendor/autoload.php'; use Josantonius\ErrorHandler\ErrorHandler;
如果您已手动安装,使用它
require_once __DIR__ . '/ErrorHandler.php'; use Josantonius\ErrorHandler\ErrorHandler;
使用方法
此库的使用示例
/** * It is recommended to instantiate the class in a base file as the index.php */ new ErrorHandler; /** * Optionally you can enter one or more methods to be executed instead the * default view. The indicated method will receive an array with the * following parameters: * * [ * 'type' => 'Error|Exception', * 'message' => 'exception|error message', * 'file' => 'exception|error file', * 'line ' => 'exception|error line', * 'code' => 'exception|error code', * 'http-code' => 'HTTP response status code', * 'mode' => 'PHP|HHVM', * ]; * */ $class = $this; $method = 'customMethodResponse'; $times = 0; $default = true; ErrorHandler::SetCustomMethod($class, $method, $times, $default);
测试
$ git clone https://github.com/Josantonius/PHP-ErrorHandler.git
$ cd PHP-ErrorHandler
$ composer install
使用 PHPUnit 运行单元测试
$ composer phpunit
$ composer phpcs
使用 PHP Mess Detector 测试以检测代码风格的不一致性
$ composer phpmd
运行所有之前的测试
$ composer tests
图片
☑ 待办事项
- 添加新功能。
- 改进测试。
- 改进文档。
- 重构禁用代码风格规则的代码。请参阅 phpmd.xml 和 .php_cs.dist。
贡献
拉取请求
- 分叉并克隆.
- 运行命令
composer install
安装依赖。这也会安装 开发依赖。 - 运行命令
composer fix
执行代码标准修复器。 - 运行 测试。
- 创建一个 分支,提交,推送到远程,并发送给我一个 拉取请求。
仓库
此仓库的文件结构是由 PHP-Skeleton 创建的。
许可证
本项目遵循 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。
版权
2016 - 2018 Josantonius,josantonius.com
如果您觉得这个项目有用,请告诉我 😉