yeh110/think-annotation
最新稳定版本:v1.1.2
Composer 安装命令:
composer require yeh110/think-annotation
包简介
Annotation For ThinkPHP6,ThinkPHP8
README 文档
README
PHP8版本
安装
composer require yeh110/think-annotation
配置
配置文件位于
config/annotation.php
使用方法
路由注解
<?php namespace app\controller; use yeh110\annotation\Inject; use yeh110\annotation\route\Get; use yeh110\annotation\route\Group; use yeh110\annotation\route\Middleware; use yeh110\annotation\route\Resource; use yeh110\annotation\route\Route; use think\Cache; use think\middleware\SessionInit; #[Group("bb")] #[Resource("aa")] #[Middleware([SessionInit::class])] class IndexController { #[Inject] protected Cache $cache; public function index() { //... } #[Route('GET','xx')] public function xx() { //... } #[Get('cc')] public function cc() { //... } }
默认会扫描controller目录下的所有类
可对个别目录单独配置
//... 'route' => [ 'enable' => true, 'controllers' => [ app_path('controller/admin') => [ 'name' => 'admin/api', 'middleware' => [], ], root_path('other/controller') ], ], //...
模型注解
<?php namespace app\model; use think\Model; use yeh110\annotation\model\relation\HasMany; #[HasMany("articles", Article::class, "user_id")] class User extends Model { //... }
权限注解
<?php namespace app\controller; use yeh110\annotation\auth\Auths; use yeh110\annotation\auth\Auth; #[Auths("控制器名称")] class User { #[Auth('方法一')] public function xx() { //... } #[Auth('方法二', ['auth'=>false])] public function xx() { //... } //... }
权限注解读取
<?php use yeh110\annotation\InteractsWithAuths; $dir = app_path('controller'); $data = InteractsWithAuths::run($dir); print_r($data);
统计信息
- 总下载量: 63
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-04-07