123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- namespace EasySwoole\HttpAnnotation\Tests\TestController;
- use EasySwoole\Component\Context\ContextManager;
- use EasySwoole\HttpAnnotation\AnnotationController;
- use EasySwoole\HttpAnnotation\AnnotationTag\Api;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiAuth;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiDescription;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiFail;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiFailParam;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroup as ApiGroupTag;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroupAuth;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroupDescription;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiRequestExample;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiSuccess;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiSuccessParam;
- use EasySwoole\HttpAnnotation\AnnotationTag\CircuitBreaker;
- use EasySwoole\HttpAnnotation\AnnotationTag\Context;
- use EasySwoole\HttpAnnotation\AnnotationTag\Di;
- use EasySwoole\HttpAnnotation\AnnotationTag\Inject;
- use EasySwoole\HttpAnnotation\AnnotationTag\InjectParamsContext;
- use EasySwoole\HttpAnnotation\AnnotationTag\Method;
- use EasySwoole\HttpAnnotation\AnnotationTag\Param;
- use EasySwoole\HttpAnnotation\Exception\Annotation\ParamValidateError;
- class Annotation extends AnnotationController
- {
-
- public $di;
-
- public $context;
-
- public $inject;
-
- function func()
- {
- }
- function index()
- {
- $this->response()->write('index');
- }
-
- function allowPostMethod()
- {
- $this->response()->write('allowPostMethod');
- }
-
- protected function onRequest(?string $action): ?bool
- {
- return parent::onRequest($action);
- }
- function onException(\Throwable $throwable): void
- {
- if($throwable instanceof ParamValidateError){
- $this->response()->write("PE-{$throwable->getValidate()->getError()->getField()}");
- }else{
- throw $throwable;
- }
- }
-
- function param1()
- {
- $this->response()->write($this->request()->getRequestParam('param1'));
- }
-
- function param2()
- {
- $p1 = $this->request()->getRequestParam('param1');
- $p2 = $this->request()->getRequestParam('param2');
- $this->response()->write($p1 + $p2);
- }
-
- function param3()
- {
-
- $p1 = $this->request()->getRequestParam('param1');
- $p2 = $this->request()->getRequestParam('groupParamA');
- $this->response()->write($p1 + $p2);
- }
- function paramExport1($groupParamA)
- {
- $this->response()->write($groupParamA);
- }
-
- function paramExport2($groupParamA,$exp)
- {
- $this->response()->write($exp);
- }
-
- function injectParam1()
- {
- $this->response()->write(implode("|",ContextManager::getInstance()->get('data')));
- }
-
- function injectParam2()
- {
- $this->response()->write(implode("|",ContextManager::getInstance()->get('data')));
- }
- public function inject()
- {
- $this->response()->write($this->inject->index());
- }
- public function injectGetString()
- {
- $this->response()->write($this->inject->getString());
- }
- public function injectGetArray()
- {
- $this->response()->write(json_encode($this->inject->getArray()));
- }
- protected function gc()
- {
-
- }
- }
|