josantonius/errorhandler

此包已被废弃,不再维护。作者建议使用 josantonius/error-handler 包。

PHP 异常和错误处理库。

1.1.8 2018-01-16 02:06 UTC

This package is auto-updated.

Last update: 2022-08-10 16:32:44 UTC


README

Latest Stable Version Latest Unstable Version License Codacy Badge Total Downloads Travis PSR2 PSR4 CodeCov

西班牙语版本

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

或者 手动安装

下载 ErrorHandler.php:

$ wget https://raw.githubusercontent.com/Josantonius/PHP-ErrorHandler/master/src/ErrorHandler.php

可用方法

此库中的可用方法

- 设置自定义方法以渲染

ErrorHandler::setCustomMethod($class, $method, $repeat, $default);
属性 描述 类型 必需 默认
$class 类名或类对象。 callable
$method 方法名。 字符串
$repeat 重复方法的次数。 整数 0
$default 显示默认视图。 布尔型 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);

测试

要运行 测试,您只需要 Composer 并执行以下操作

$ git clone https://github.com/Josantonius/PHP-ErrorHandler.git

$ cd PHP-ErrorHandler

$ composer install

使用 PHPUnit 运行单元测试

$ composer phpunit

使用 PSR2 代码标准测试使用 PHPCS

$ composer phpcs

运行 PHP Mess Detector 测试以检测代码风格的不一致性

$ composer phpmd

运行所有之前的测试

$ composer tests

图片

image image image image

☑ TODO

  • 添加新功能。
  • 改进测试。
  • 改进文档。
  • 重构禁用代码风格规则的代码。请参阅 phpmd.xml.php_cs.dist

贡献

如果您想帮忙,请查看问题列表待办事项清单

拉取请求

  • 分支并克隆.
  • 运行命令 composer install 安装依赖项。这还将安装开发依赖项
  • 运行命令 composer fix 执行代码规范修复器。
  • 运行测试
  • 创建一个 分支提交推送,并给我发送一个拉取请求

仓库

此仓库的文件结构是用 PHP-Skeleton 创建的。

许可证

本项目采用 MIT 许可证。有关更多信息,请参阅LICENSE 文件。

版权

2016 - 2018 Josantonius, josantonius.com

如果您觉得它有用,请告诉我 😉

您可以通过 Twitter 或我的电子邮件联系我。