更新基础架构

This commit is contained in:
技术老胡
2026-01-27 09:07:38 +08:00
parent 28f1a2855c
commit 4a34feec54
36 changed files with 1289 additions and 540 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace support\exception;
use Throwable;
use Webman\Exception\ExceptionHandler;
use Webman\Http\Request;
use Webman\Http\Response;
use support\exception\BusinessException;
/**
* 自定义异常处理器
* 基于 webman 的 ExceptionHandler 扩展,统一处理业务异常
*/
class Handler extends ExceptionHandler
{
/**
* 不需要记录日志的异常类型
*/
public $dontReport = [
BusinessException::class,
];
/**
* 报告异常(记录日志)
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* 渲染异常响应
*/
public function render(Request $request, Throwable $exception): Response
{
// 业务异常优先走异常自身的 render参考官方文档自定义业务异常
if ($exception instanceof \Webman\Exception\BusinessException) {
if (method_exists($exception, 'render')) {
$response = $exception->render($request);
if ($response instanceof Response) {
return $response;
}
}
}
// 其他异常使用父类默认处理debug=true 时带 trace字段沿用 webman 默认)
return parent::render($request, $exception);
}
}

4
support/functions.php Normal file
View File

@@ -0,0 +1,4 @@
<?php
/**
* Here is your custom functions.
*/