123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace EasySwoole\HttpAnnotation\Tests\TestController;
- use EasySwoole\HttpAnnotation\AnnotationController;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiAuth;
- use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroupAuth;
- use EasySwoole\HttpAnnotation\Exception\Annotation\ParamValidateError;
- /**
- * Class Param
- * @package EasySwoole\HttpAnnotation\Tests\TestController
- * @ApiGroupAuth(name="groupAuth",required="",notEmpty="")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="groupParam",required="",notEmpty="")
- */
- class Param extends AnnotationController
- {
- /**
- * @ApiAuth(name="onRequestAuth",required="",notEmpty="")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="onRequestParam",required="",notEmpty="")
- */
- public function onRequest(?string $action): ?bool
- {
- return parent::onRequest($action); // TODO: Change the autogenerated stub
- }
- /**
- * @ApiAuth(name="auth",required="",notEmpty="")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="param",required="",notEmpty="")
- */
- public function index()
- {
- $this->response()->write(json_encode($this->request()->getQueryParams()));
- }
- /**
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="foo",lessThanWithColumn="bar")
- */
- public function lessThanWithColumn()
- {
- }
- /**
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="columnA",betweenMbLen={3,5})
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="columnB",mbLength="3")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="columnC",mbLengthMax="3")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="columnD",mbLengthMin="1")
- */
- public function mbLengthWithColumn()
- {
- }
- /**
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="foo",greaterThanWithColumn="bar")
- */
- public function greaterThanWithColumn()
- {
- }
- /**
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="foo",required="",notEmpty="",deprecated=true)
- */
- public function deprecated()
- {
- }
- /**
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="foo",required="",notEmpty="")
- */
- public function notDeprecated()
- {
- }
- /**
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="string",type="string")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="int",type="int")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="float",type="float")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="bool",type="bool")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="json",type="json")
- * @\EasySwoole\HttpAnnotation\AnnotationTag\Param(name="array",type="array")
- */
- public function paramType(string $string, int $int, float $float, bool $bool, \stdClass $json, array $array)
- {
- if (gettype($string) !== 'string' ||
- gettype($int) !== 'integer' ||
- gettype($float) !== 'double' ||
- gettype($bool) !== 'boolean' ||
- gettype($json) !== 'object' ||
- gettype($array) !== 'array'
- ) {
- $this->response()->write('error');
- } else {
- $this->response()->write('success');
- }
- }
- protected function onException(\Throwable $throwable): void
- {
- if ($throwable instanceof ParamValidateError) {
- $validate = $throwable->getValidate();
- $rule = $validate->getError()->getErrorRule();
- if (in_array($rule, ['lessThanWithColumn', 'greaterThanWithColumn',"betweenMbLen","mbLength","mbLengthMax","mbLengthMin"])) {
- throw new \Exception($validate->getError()->__toString());
- }
- }
- parent::onException($throwable); // TODO: Change the autogenerated stub
- }
- }
|