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 方法名。 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);

测试

要运行 测试,您只需要 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

☑ 待办事项

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

贡献

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

拉取请求

  • 分叉并克隆.
  • 运行命令 composer install 安装依赖。这也会安装 开发依赖
  • 运行命令 composer fix 执行代码标准修复器。
  • 运行 测试
  • 创建一个 分支提交推送到远程,并发送给我一个 拉取请求

仓库

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

许可证

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

版权

2016 - 2018 Josantonius,josantonius.com

如果您觉得这个项目有用,请告诉我 😉

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