Skip to content

Commit

Permalink
调整注解执行逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Jun 30, 2020
1 parent ccfd2e1 commit 752d44b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/AnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ protected function __handleAnnotationParams(?string $actionName):array
$params[$param->name] = $param;
}
}
$realParamsKey = [];
$realParams = [];
if(!empty($annotations['Param'])){
foreach ($annotations['Param'] as $param){
$params[$param->name] = $param;
$realParamsKey[$param->name];
$realParams[$param->name] = null;
}
}

Expand Down Expand Up @@ -319,35 +319,39 @@ protected function __handleAnnotationParams(?string $actionName):array
}
}

//合并参数
$data = $actionArgs + $this->request()->getRequestParam();
if(!$validate->validate($data)){
$ex = new ParamValidateError("validate fail for column {$validate->getError()->getField()}");
$ex->setValidate($validate);
throw $ex;
}
//仅仅返回@Param所指定的参数
foreach ($realParams as $key => $value){
$realParams[$key] = $actionArgs[$key];
}
if($injectKey){
if($filterNull){
foreach ($actionArgs as $key => $arg){
foreach ($realParams as $key => $arg){
if($arg === null){
unset($actionArgs[$key]);
unset($realParams[$key]);
}else if($filterEmpty){
if(empty($arg)){
unset($actionArgs[$key]);
unset($realParams[$key]);
}
}

}
}else if($filterEmpty){
foreach ($actionArgs as $key => $arg){
if(empty($arg)){
unset($actionArgs[$key]);
unset($realParams[$key]);
}
}
}
ContextManager::getInstance()->set($injectKey,$actionArgs);
}
//合并参数
$data = $actionArgs + $this->request()->getRequestParam();
if(!$validate->validate($data)){
$ex = new ParamValidateError("validate fail for column {$validate->getError()->getField()}");
$ex->setValidate($validate);
throw $ex;
ContextManager::getInstance()->set($injectKey,$realParams);
}
return $actionArgs;
return $realParams;
}
return [];
}
Expand Down

0 comments on commit 752d44b

Please sign in to comment.