Skip to content

Commit

Permalink
修复循序引用导致request对象不释放
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Oct 11, 2023
1 parent c50231e commit ebb66bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
28 changes: 15 additions & 13 deletions src/AnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())){
Expand Down Expand Up @@ -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();
}
}
}
9 changes: 8 additions & 1 deletion src/Validator/AbstractInterface/AbstractValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

/**
Expand Down

0 comments on commit ebb66bd

Please sign in to comment.