PHP code example of keygn / tp6-annotation

1. Go to this page and download the library: Download keygn/tp6-annotation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

keygn / tp6-annotation example snippets


    
    // +----------------------------------------------------------------------
    // | 控制台配置
    // +----------------------------------------------------------------------
    return [
        // 指令定义
        'commands' => [
            \keygn\tp6\annotation\command\Annotation::class,
            \keygn\tp6\annotation\command\Handler::class
        ],
    ];
    

  php think make:annotation User
  

  
  declare (strict_types = 1);
  
  namespace app\annotation;
  
  use Doctrine\Common\Annotations\Annotation;
  
  /**
   * class User
   * @package app\annotation
   * @Annotation
   * @Target({"METHOD","CLASS"}) # 不需要进行类注解去掉"CLASS",不需要方法注解去掉"METHOD"
   */
  class User extends Annotation
  {
      // TODO 完成你对注解字段的定义
  }
  

  php think make:handler User
  

  
  declare (strict_types = 1);
  
  namespace app\annotation\handler;
  
  use Doctrine\Common\Annotations\Annotation;
  use \keygn\tp6\annotation\handler\Handler;
  
  class User extends Handler
  {
      public function cls(\ReflectionClass $refClass, Annotation $annotation, \think\Route &$route)
      {
          // TODO: 完成类注解的操作
      }
  
      public function func(\ReflectionMethod $refMethod, Annotation $annotation, \think\route\RuleItem &$rule)
      {
          // TODO: 完成方法注解的操作
      }
  }
  

   return [
       'custom' => [
           # 格式:注解类 => 注解操作类
           \app\annotation\User::class => \app\annotation\handler\User::class, # 这里写上你的注解
       ]
   ];