Action注解

@Api

标记这个methodapi.

  • name 注解文档的api标题.
  • path 路由(可注册到fast-route)
  • version api版本号(暂时没用)
  • description api描述(新版本建议使用@ApiDescription
  • deprecated 注解文档标注此api为废弃(将会不可访问,返回423状态)

@ApiDescription

  • value api描述

@Method

  • allow 验证请求方法

注入fast-route

  1. <?php
  2. namespace App\HttpController;
  3. use EasySwoole\Http\AbstractInterface\AbstractRouter;
  4. use EasySwoole\HttpAnnotation\Utility\Scanner;
  5. use FastRoute\RouteCollector;
  6. class Router extends AbstractRouter
  7. {
  8. function initialize(RouteCollector $routeCollector)
  9. {
  10. $scanner = new Scanner();
  11. $scanner->mappingRouter($routeCollector, EASYSWOOLE_ROOT . '/App/HttpController', 'App\HttpController');
  12. }
  13. }

这样就可以把@Api注解中的path注入到fast-route,具体用法查看动态路由

example

  1. <?php
  2. namespace App\HttpController;
  3. use EasySwoole\HttpAnnotation\AnnotationController;
  4. use EasySwoole\HttpAnnotation\AnnotationTag\Api;
  5. use EasySwoole\HttpAnnotation\AnnotationTag\ApiDescription;
  6. use EasySwoole\HttpAnnotation\AnnotationTag\Method;
  7. /**
  8. * Class Test
  9. * @package App\HttpController
  10. */
  11. class Test extends AnnotationController
  12. {
  13. /**
  14. * @Api(name="test-index",path="/test/index",version="1.0")
  15. * @ApiDescription("test-index-action")
  16. */
  17. public function index()
  18. {
  19. }
  20. /**
  21. * @Api(name="test-deprecated",path="/test/index",version="1.0",deprecated=true)
  22. */
  23. public function deprecated()
  24. {
  25. }
  26. /**
  27. * @Api(name="test-post")
  28. * @Method(allow={POST,PUT})
  29. */
  30. public function post(){
  31. }
  32. }