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

10
config/app.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
return [
'name' => 'FendxPHP',
'version' => '1.0.0',
'timezone' => 'Asia/Shanghai',
'debug' => true,
'env' => 'development',
];

11
config/cache.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
return [
'host' => '127.0.0.1',
'port' => 6379,
'password' => '',
'database' => 0,
'timeout' => 3.0,
'local_cache' => true,
];

120
config/config.php Normal file
View File

@@ -0,0 +1,120 @@
<?php
declare(strict_types=1);
return [
'app' => require __DIR__ . '/app.php',
'database' => require __DIR__ . '/database.php',
'cache' => require __DIR__ . '/cache.php',
'security' => [
'token' => [
'secret' => 'your-secret-key-here',
'expire' => 7200, // 2小时
'issuer' => 'fendx',
'audience' => 'fendx-client',
'secret_key' => bin2hex(random_bytes(32)),
'expires_in' => 7200,
'algorithm' => 'HS256',
'cache_prefix' => 'token:',
],
'rate_limit' => 60,
'idempotent_ttl' => 300,
'super_admin_ids' => [1],
],
'log' => [
'level' => 'INFO',
'async' => true,
'max_files' => 30,
'max_size' => '10MB',
],
'web' => [
'cors' => [
'enabled' => true,
'origins' => ['*'],
'methods' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
'headers' => ['Content-Type', 'Authorization', 'X-Requested-With'],
'credentials' => true,
],
],
'file' => [
'type' => 'local',
'root' => dirname(__DIR__) . '/runtime/storage',
'url_prefix' => '/storage'
],
'monitor' => [
'enabled' => true,
'sample_rate' => 1.0,
'health_timeout' => 5.0,
'disk_threshold' => 0.9,
'enabled_checks' => [
'database',
'cache',
'filesystem',
'memory',
'disk'
],
'alert_thresholds' => [
'memory_usage' => 0.8,
'cpu_usage' => 0.8,
'response_time' => 1.0,
'error_rate' => 0.05
],
'error_tracking' => [
'enabled' => true,
'max_errors' => 1000,
'retention_period' => 3600,
'notify_threshold' => 10,
'group_similar' => true,
'track_stack_trace' => true,
'track_request_info' => true
],
'alerts' => [
'enabled' => true,
'max_alerts' => 500,
'retention_period' => 7200,
'channels' => ['log'],
'thresholds' => [
'error_rate' => 0.05,
'memory_usage' => 0.9,
'disk_usage' => 0.95,
'response_time' => 2.0,
'critical_errors' => 5
],
'cooldown' => [
'error_rate' => 300,
'memory_usage' => 600,
'disk_usage' => 600,
'response_time' => 300,
'critical_errors' => 1800
]
],
'log_analysis' => [
'enabled' => true,
'log_paths' => [dirname(__DIR__) . '/runtime/logs'],
'max_file_size' => 50 * 1024 * 1024,
'index_cache_ttl' => 300,
'search_limit' => 1000,
'real_time' => true,
'patterns' => [
'error' => '/\b(ERROR|FATAL|CRITICAL)\b/i',
'warning' => '/\b(WARNING|WARN)\b/i',
'exception' => '/\b(Exception|Throwable)\b/i',
'sql' => '/\b(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER)\b/i',
'slow_query' => '/slow.*query|query.*slow/i',
'memory' => '/memory|Memory/i',
'performance' => '/performance|slow|timeout/i',
'security' => '/security|auth|login|logout|unauthorized/i'
]
],
'log_visualization' => [
'chart_width' => 800,
'chart_height' => 400,
'max_data_points' => 100,
'theme' => 'light'
]
],
];

18
config/database.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
return [
'default' => [
'host' => '127.0.0.1',
'port' => 3306,
'dbname' => 'fendx',
'username' => 'fendx',
'password' => 'PPJEknapecybS8hM',
'charset' => 'utf8mb4',
'options' => [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
],
],
];

9
config/routes.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
use Fendx\Web\Route\Router;
return function (Router $router) {
$router->get('/', [App\Controller\HomeController::class, 'index']);
$router->get('/health', [App\Controller\HomeController::class, 'health']);
};