From d0018a01732b0608969947280877a475e3ed0d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=90=A6?= Date: Mon, 10 Aug 2026 14:42:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96=E3=80=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursor/rules/Code-Standards.mdc | 15 ++++++++++++--- composer.json | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.cursor/rules/Code-Standards.mdc b/.cursor/rules/Code-Standards.mdc index 166980d9..f7c71173 100644 --- a/.cursor/rules/Code-Standards.mdc +++ b/.cursor/rules/Code-Standards.mdc @@ -1,8 +1,16 @@ --- -description: nl-admin 后端(Laravel + 自动路由)代码规范 +description: nl-admin 后端(Laravel 13 + PHP 8.3 + 自动路由)代码规范 alwaysApply: true --- +# 技术栈基线(升级后必守) + +- **Laravel 13**(`composer.json`:`laravel/framework: ^13.0`) +- **PHP ≥ 8.3**(Laravel 13 官方最低要求;禁止按 8.2 写法或回退依赖) +- 应用启动走 `bootstrap/app.php` 的 fluent API(`withRouting` / `withMiddleware` / `withExceptions`),**不要**再按旧版 `Http/Kernel` 拆分中间件与异常 +- 代码风格优先 `laravel/pint`;测试栈为 PHPUnit 12 +- Laravel 13 的 PHP Attribute(如 `#[Middleware]`、`#[Authorize]`、Job 的 `#[Tries]` 等)可用,但本项目的 **HTTP 谓词仍以 PHPDoc `@Method` 为准**(`autoRouteRegister` 扫描依赖它) + # 基础规范(所有项目通用) 1. 写代码的时候要补充详细的中文注释(每个方法是干嘛的,为什么要这样写),如果是工作区,则所有项目都适用该规则 @@ -38,7 +46,7 @@ alwaysApply: true - 禁止在 Controller 直接复用业务逻辑,必须抽到 Service - 禁止在多个 Service 中复制粘贴相同逻辑,必须抽到 `app/Service/common/` -- 若后续引入队列:统一放 `app/Jobs/<域>/`,实现 `ShouldQueue` + `Queueable`,必要时 `->onQueue('xxx')`(当前仓库尚未建 Jobs,按需新增) +- 若后续引入队列:统一放 `app/Jobs/<域>/`,实现 `ShouldQueue` + `Queueable`;单 Job 可用 `->onQueue('xxx')`,多 Job 默认路由优先用 Laravel 13 的 `Queue::route(Job::class, connection: 'redis', queue: 'xxx')` 集中声明(当前仓库尚未建 Jobs,按需新增) ## 路由规范(自动注册,禁止手写业务路由) @@ -64,9 +72,10 @@ alwaysApply: true ## 常量管理 -- 枚举值必须用 PHP 8.1 enum 放 `app/Enum/`,禁止在代码中散落魔法数字 +- 枚举值必须用 PHP native `enum`(PHP 8.3+)放 `app/Enum/`,禁止在代码中散落魔法数字 - 状态约定以现有枚举为准:`StatusEnum` / `UserStatusEnum` 为 **0=正常,1=禁用/冻结**(不要写成其他项目的 1 启用 0 禁用) - 新增状态类字段优先复用或扩展 `app/Enum/` 中的枚举 +- CSRF / 请求伪造防护中间件类名以 Laravel 13 为准:`PreventRequestForgery`(旧名 `VerifyCsrfToken` 仅为兼容别名,新代码不要再写) ## 命名规范 diff --git a/composer.json b/composer.json index df02b4a1..aa7041e3 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "keywords": ["laravel", "framework"], "license": "MIT", "require": { - "php": "^8.2", + "php": "^8.3", "ext-zip": "*", "firebase/php-jwt": "^7", "laravel/framework": "^13.0",