# think-annotation **Repository Path**: LazySkills/think-annotation ## Basic Information - **Project Name**: think-annotation - **Description**: ThinkPHP6注解扩展增强版 - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 2 - **Created**: 2019-11-25 - **Last Updated**: 2025-09-11 ## Categories & Tags **Categories**: webframework **Tags**: None ## README # think-annotation for ThinkPHP6 ## 安装 > composer require lazyskills/think-annotation ## 配置 > 配置文件位于 `config/annotation.php` ## 使用方法 ~~~ [ \think\annotation\command\Annotation::class, \think\annotation\command\Handler::class ], ]; ``` - 生成注解类(annotation) 命令行操作:例如生成一个 User 类注解 ```php php think make:annotation User ``` 生成完成的注解类,如下: ```php 只需要完成 TODO 位置对注解参数的定义,可以参考TP6自带的注解类 - 生成注解处理器类(handler) 命令行操作:例如生成一个 User 类注解处理器类 ```php php think make:handler User ``` 生成完成的注解类,如下: ```php 只需要完成 TODO 注解的解释进行操作处理哦, `cls()`方法是针对注解类`@Target()`中包含`CLASS`时才会被调用 > ,`func()`方法是针对注解类`@Target()`中包含`METHOD`时才会被调用。 参数说明: | 参数名 | 简介 | | ---- | ---- | | $refClass | `\ReflectionClass` 当前注解类的反射对象 | | $annotation | 当前类注解的参数对象(`cls和func的annotation一样`) | | $route | 当前类的`TP6` `\think\Route`路由对象 | | $refMethod | `\ReflectionMethod` 当前注解类访问方法的反射对象 | | $rule | 当前方法的`TP6` `\think\route\RuleItem` 路由规则对象 | > 上述只是对参数做的阐述,实际参数意义和作用具体看自身业务。 - 添加到用户自定义的注解配置中 文件位置: `config/annotation.php` 添加内容: ```PHP return [ 'inject' => [ 'enable' => true, 'namespaces' => [], ], 'route' => [ 'enable' => true, 'controllers' => [], ], 'ignore' => [], 'management' => true, 'custom' => [ # 格式:注解类 => 注解操作类 \app\annotation\User::class => \app\annotation\handler\User::class, # 这里写上你的注解 ] ]; ``` IDE Support ----------- Some IDEs already provide support for annotations: - Eclipse via the Symfony2 Plugin - PHPStorm via the PHP Annotations Plugin or the Symfony2 Plugin