feat(database): 添加用户角色权限系统及相关监控功能

- 创建用户表(users)包含基本信息和认证字段
- 创建角色表(roles)用于权限控制
- 创建权限表(permissions)定义系统权限
- 创建用户角色关联表(user_roles)建立用户与角色关系
- 创建角色权限关联表(role_permissions)建立角色与权限关系
- 创建迁移记录表(migrations)追踪数据库变更
- 添加AdminController提供管理员面板功能
- 实现系统监控、配置管理、缓存清理等功能
- 添加AOP切面编程支持的各种通知类型
- 实现告警管理AlertManager支持多渠道告警
- 添加文档注解接口规范
This commit is contained in:
Lawson
2026-04-08 17:00:28 +08:00
commit 2782d765fb
270 changed files with 107192 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
{
"name": "fendx/common",
"description": "FendxPHP Common Module - 公共工具、常量、枚举、异常",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Lawson",
"email": "lawson@fendx.cn"
}
],
"require": {
"php": ">=8.1"
},
"autoload": {
"psr-4": {
"Fendx\\Common\\": "src/"
}
},
"minimum-stability": "stable",
"prefer-stable": true
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Fendx\Common\Constant;
class HttpCode
{
public const OK = 200;
public const CREATED = 201;
public const NO_CONTENT = 204;
public const BAD_REQUEST = 400;
public const UNAUTHORIZED = 401;
public const FORBIDDEN = 403;
public const NOT_FOUND = 404;
public const METHOD_NOT_ALLOWED = 405;
public const CONFLICT = 409;
public const INTERNAL_SERVER_ERROR = 500;
public const NOT_IMPLEMENTED = 501;
public const BAD_GATEWAY = 502;
public const SERVICE_UNAVAILABLE = 503;
}

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Fendx\Common\Exception;
use Throwable;
abstract class BaseException extends \Exception
{
protected int $errorCode = 0;
protected array $data = [];
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null, array $data = [])
{
parent::__construct($message, $code, $previous);
$this->errorCode = $code;
$this->data = $data;
}
public function getErrorCode(): int
{
return $this->errorCode;
}
public function getData(): array
{
return $this->data;
}
public function toArray(): array
{
return [
'code' => $this->getErrorCode(),
'message' => $this->getMessage(),
'data' => $this->getData()
];
}
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Fendx\Common\Exception;
class BusinessException extends BaseException
{
public function __construct(int $code, string $messageKey, array $data = [], ?\Throwable $previous = null)
{
$message = $this->getMessageByKey($messageKey, $data);
parent::__construct($message, $code, $previous, $data);
}
private function getMessageByKey(string $key, array $data = []): string
{
$messages = [
'DB_CONNECT_FAILED' => '数据库连接失败: {message}',
'VALIDATION_FAILED' => '参数验证失败',
'UNAUTHORIZED' => '未授权访问',
'FORBIDDEN' => '禁止访问',
'NOT_FOUND' => '资源不存在',
'SERVER_ERROR' => '服务器内部错误',
];
$message = $messages[$key] ?? $key;
foreach ($data as $k => $v) {
$message = str_replace('{' . $k . '}', (string)$v, $message);
}
return $message;
}
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace Fendx\Common\Util;
class ArrayHelper
{
public static function get(array $array, string $key, mixed $default = null): mixed
{
if ($key === '') {
return $default;
}
$keys = explode('.', $key);
$value = $array;
foreach ($keys as $k) {
if (!is_array($value) || !array_key_exists($k, $value)) {
return $default;
}
$value = $value[$k];
}
return $value;
}
public static function set(array &$array, string $key, mixed $value): void
{
$keys = explode('.', $key);
$current = &$array;
foreach ($keys as $k) {
if (!is_array($current)) {
$current = [];
}
if (!array_key_exists($k, $current)) {
$current[$k] = [];
}
$current = &$current[$k];
}
$current = $value;
}
public static function merge(array ...$arrays): array
{
$result = [];
foreach ($arrays as $array) {
foreach ($array as $key => $value) {
if (is_int($key)) {
$result[] = $value;
} elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
$result[$key] = self::merge($result[$key], $value);
} else {
$result[$key] = $value;
}
}
}
return $result;
}
}