Skip to content

Commit

Permalink
up fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Apr 30, 2020
1 parent 7bb0823 commit 175f700
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
25 changes: 23 additions & 2 deletions src/AnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ abstract class AnnotationController extends Controller
private $methodAnnotations = [];
private $propertyAnnotations = [];
private $annotation;
private $l = [];

public function __construct(?Annotation $annotation = null)
{
Expand Down Expand Up @@ -145,8 +144,12 @@ protected function __annotationHook(string $actionName)
}

$injectKey = null;
$filterNull = false;
$filterEmpty = false;
if(!empty($annotations['InjectParamsContext'])){
$injectKey = $annotations['InjectParamsContext'][0]->key;
$filterNull = $annotations['InjectParamsContext'][0]->filterNull;
$filterEmpty = $annotations['InjectParamsContext'][0]->filterEmpty;
}
/*
* 参数构造与validate验证
Expand Down Expand Up @@ -213,7 +216,7 @@ protected function __annotationHook(string $actionName)
$value = $param->defaultValue;
}

if(!empty($param->preHandler)){
if(!empty($param->preHandler) && $value !== null){
if(is_callable($param->preHandler)){
$value = call_user_func($param->preHandler,$value);
}else{
Expand All @@ -237,6 +240,24 @@ protected function __annotationHook(string $actionName)
}
}
if($injectKey){
if($filterNull){
foreach ($actionArgs as $key => $arg){
if($arg === null){
unset($actionArgs[$key]);
}else if($filterEmpty){
if(empty($arg)){
unset($actionArgs[$key]);
}
}

}
}else if($filterEmpty){
foreach ($actionArgs as $key => $arg){
if(empty($arg)){
unset($actionArgs[$key]);
}
}
}
ContextManager::getInstance()->set($injectKey,$actionArgs);
}
//合并参数
Expand Down
16 changes: 13 additions & 3 deletions src/AnnotationTag/InjectParamsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace EasySwoole\HttpAnnotation\AnnotationTag;

use EasySwoole\Annotation\AbstractAnnotationTag;
use EasySwoole\Annotation\ValueParser;

/**
* Class InjectParamsContext
Expand All @@ -13,6 +14,15 @@
class InjectParamsContext extends AbstractAnnotationTag
{
public $key = 'INJECT_PARAMS';
/**
* @var bool
*/
public $filterNull = false;

/**
* @var bool
*/
public $filterEmpty = false;

public function tagName(): string
{
Expand All @@ -21,9 +31,9 @@ public function tagName(): string

public function assetValue(?string $raw)
{
parse_str($raw,$str);
if(!empty($str['key'])){
$this->key = trim($str['key']," \t\n\r\0\x0B\"'");
$allParams = ValueParser::parser($raw);
foreach ($allParams as $key => $value){
$this->$key = $value;
}
}
}

0 comments on commit 175f700

Please sign in to comment.