更新基础架构

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,16 @@
<?php
namespace app\exceptions;
/**
* 认证失败(账号或密码错误)
*/
class AuthFailedException extends BusinessException
{
public function __construct(string $message = '账号或者密码错误', int $bizCode = 400, mixed $data = null)
{
parent::__construct($message, $bizCode, $data);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace app\exceptions;
/**
* 业务基础异常
*
* 说明:
* - 继承 webman 的 BusinessException让框架自动捕获并渲染
* - 重写 render() 以对齐前端期望字段code/message/data
*/
class BusinessException extends \support\exception\BusinessException
{
public function __construct(string $message = '', int $bizCode = 500, array $data = [])
{
parent::__construct($message, $bizCode);
$this->data($data);
}
public function getBizCode(): int
{
return (int)$this->getCode();
}
// 保持与 webman BusinessException 方法签名兼容
public function getData(): array
{
return parent::getData();
}
/**
* 自定义渲染
* - json 请求:返回 {code,message,data}
* - 非 json返回文本
*/
public function render(\Webman\Http\Request $request): ?\Webman\Http\Response
{
if ($request->expectsJson()) {
return json([
'code' => $this->getBizCode() ?: 500,
'message' => $this->getMessage(),
'data' => $this->getData(),
]);
}
return new \Webman\Http\Response(200, [], $this->getMessage());
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace app\exceptions;
/**
* 权限不足
*/
class ForbiddenException extends BusinessException
{
public function __construct(string $message = '无访问权限', int $bizCode = 403, mixed $data = null)
{
parent::__construct($message, $bizCode, $data);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace app\exceptions;
/**
* 未认证或登录过期
*/
class UnauthorizedException extends BusinessException
{
public function __construct(string $message = '登录状态已过期', int $bizCode = 401, mixed $data = null)
{
parent::__construct($message, $bizCode, $data);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace app\exceptions;
/**
* 参数校验异常
*/
class ValidationException extends BusinessException
{
public function __construct(string $message = '参数校验失败', int $bizCode = 422, mixed $data = null)
{
parent::__construct($message, $bizCode, $data);
}
}