From ebb66bded4465e8e88423979f5289fec11b15c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=9A=84=E5=A6=82=E6=9E=9C?= Date: Wed, 11 Oct 2023 14:43:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AA=E5=BA=8F=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=AF=BC=E8=87=B4request=E5=AF=B9=E8=B1=A1=E4=B8=8D?= =?UTF-8?q?=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AnnotationController.php | 28 ++++++++++--------- .../AbstractInterface/AbstractValidator.php | 9 +++++- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/AnnotationController.php b/src/AnnotationController.php index 9608cd3..0e23b2a 100644 --- a/src/AnnotationController.php +++ b/src/AnnotationController.php @@ -40,21 +40,9 @@ public function __hook(?array $actionArg = [],?array $onRequestArg = null) $this->preHandleProperty(); $onRequestArg = $this->runParamsValidate($this->getActionName(),$this->request()); - $handler = function (Param $param)use(&$handler){ - if(!empty($param->subObject)){ - $temp = []; - /** @var Param $item */ - foreach ($param->subObject as $item){ - $temp[$item->name] = $handler($item); - } - return $temp; - }else{ - return $param->parsedValue(); - } - }; /** @var Param $actionParam */ foreach ($onRequestArg as $actionParam){ - $onRequestArg[$actionParam->name] = $handler($actionParam); + $onRequestArg[$actionParam->name] = self::handlerParam($actionParam); } $ref = ReflectionCache::getInstance()->getClassReflection(static::class); if($ref->hasMethod($this->getActionName())){ @@ -170,4 +158,18 @@ private function paramValidate(Param $param,array $allDefineParams,Request $requ } } } + + protected static function handlerParam(Param $param) + { + if(!empty($param->subObject)){ + $temp = []; + /** @var Param $item */ + foreach ($param->subObject as $item){ + $temp[$item->name] = self::handlerParam($item); + } + return $temp; + }else{ + return $param->parsedValue(); + } + } } \ No newline at end of file diff --git a/src/Validator/AbstractInterface/AbstractValidator.php b/src/Validator/AbstractInterface/AbstractValidator.php index 855ae93..6bded20 100644 --- a/src/Validator/AbstractInterface/AbstractValidator.php +++ b/src/Validator/AbstractInterface/AbstractValidator.php @@ -38,7 +38,14 @@ function execute(Param $param,ServerRequestInterface $request):bool if($this->isIgnoreCheck($param)){ return true; } - return $this->validate($param,$request); + try { + return $this->validate($param,$request); + } finally { + //清除循环引用 + $this->request = null; + $this->currentParam = null; + } + } /**