infira/errorhandler

此包的最新版本(v2.1.1)没有可用的许可信息。

全面的PHP错误、警告等处理器。

v2.1.1 2023-05-19 15:11 UTC

This package is auto-updated.

Last update: 2024-09-19 17:56:45 UTC


README

###全面的PHP错误、警告等处理器。

偶尔有些bug会进入生产环境,而在测试中并未出现。ErrorHandler可以捕获由php-core、用户和自定义错误产生的错误级别,并将其输出到浏览器,或者你可以创建一个自定义包装器来处理错误。下面是示例。

#安装

  • 最低要求 - PHP 8
$ composer require infira/errorhandler

#使用方法

##引发用户错误

use Infira\Error\Error;

alert("my error",['extra'=>'data']); //it's a helper to Error::trigger
Error::trigger("my error",['extra'=>'data']);

##捕获并显示错误

use Infira\Error\Handler;
require_once "vendor/autoload.php";
Handler::register();
try
{
	alert("my error",['extra'=>'data']);
	//OR
	callingNotExistingMethod();
	//OR
	echo $a
}
catch (Throwable $e) {
	echo Handler::compile($e)->getHTMLTable();
}

getHTMLTable()将输出服务器提供的一切,如alt text

就这样!你的应用程序正在捕获错误!

##使用编译后的异常数据

use Infira\Error\Handler;
require_once "vendor/autoload.php";
Handler::register();
try
{
	makeError
}
catch (Throwable $e) {
    echo "<pre>".print_r(Handler::compile($e)->toArray(); //outputs all data that has been collected
}