mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-20 23:25:35 +08:00
orgianze bootstrapper
This commit is contained in:
35
src/ZM/Bootstrap/HandleExceptions.php
Normal file
35
src/ZM/Bootstrap/HandleExceptions.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace ZM\Bootstrap;
|
||||
|
||||
use OneBot\Driver\ExceptionHandler;
|
||||
use ZM\Exception\Handler;
|
||||
|
||||
class HandleExceptions
|
||||
{
|
||||
public function bootstrap(array $config): void
|
||||
{
|
||||
// 注册全局错误处理器
|
||||
set_error_handler(function ($error_no, $error_msg, $error_file, $error_line) {
|
||||
$tips = [
|
||||
E_WARNING => ['PHP Warning: ', 'warning'],
|
||||
E_NOTICE => ['PHP Notice: ', 'notice'],
|
||||
E_USER_ERROR => ['PHP Error: ', 'error'],
|
||||
E_USER_WARNING => ['PHP Warning: ', 'warning'],
|
||||
E_USER_NOTICE => ['PHP Notice: ', 'notice'],
|
||||
E_STRICT => ['PHP Strict: ', 'notice'],
|
||||
E_RECOVERABLE_ERROR => ['PHP Recoverable Error: ', 'error'],
|
||||
E_DEPRECATED => ['PHP Deprecated: ', 'notice'],
|
||||
E_USER_DEPRECATED => ['PHP User Deprecated: ', 'notice'],
|
||||
];
|
||||
$level_tip = $tips[$error_no] ?? ['PHP Unknown: ', 'error'];
|
||||
$error = $level_tip[0] . $error_msg . ' in ' . $error_file . ' on ' . $error_line;
|
||||
logger()->{$level_tip[1]}($error);
|
||||
// 如果 return false 则错误会继续递交给 PHP 标准错误处理
|
||||
return true;
|
||||
}, E_ALL | E_STRICT);
|
||||
|
||||
// 重载异常处理器
|
||||
ExceptionHandler::getInstance()->overrideWith(new Handler());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user