PHP8注解插件

1.0.0
版本
2024-01-13
版本更新時間
29
安裝
4
star
更多內容請進入GitHub
Attribute
?? ?? ?? 基于webman使用 KingBes/Attribute 包實現(xiàn)的注解路由,中間件,權限標識,視圖標識等解決方案
PHP8的注解方案
更新日志
安裝
composer require kingbes/attribute
使用,建議結合php8的命名參數(shù)使用
use Kingbes\Attribute\Annotation; //引入
#[Annotation(
title: "首頁的",
add: ["classnew" => "class新增一個"]
)]
class IndexController
{
#[Annotation(
title: "首頁",
path: ["/index", "/", "/home"],
request: ["get", "post"],
auth: true,
add: ["newfun" => "方法新增一個"]
)]
public function index(Request $request)
{
return json(Annotation::data());
}
}
其中:return json(Annotation::data()); 得到結果
[
{
"title": "首頁的", // 默認:無Controller后綴的短class名
"class": "\\app\\controller\\IndexController", // class
"auth": false, // 權限標識 默認: false
"methods": [ // 方法數(shù)組
{
"title": "首頁", // 默認:method名
"path": [ // 路由路徑組 默認:/無Controller后綴的短class名/method名 比如:/index/home
"/index",
"/",
"/home"
],
"request": [ // 可請求方式 默認: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']
"get",
"post"
],
"middleware": [], // 中間件
"auth": true, // 權限標識
"view": false, // 視圖標識
"name": "index.index", // 路由名 默認:無Controller后綴的短class名.method名 比如: index.index
"method": "index", // method名
"newfun": "方法新增一個" // 新增數(shù)據(jù) 默認:不存在
}
],
"classnew": "class新增一個" // 新增數(shù)據(jù) 默認:不存在
}
]
class中僅title、add、auth有效