Skip to content

Commit

Permalink
新增SmallThanColumn 和BigThanColumn规则
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Aug 18, 2024
1 parent 2e6f57f commit b9a04e0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Validator/SmallThanColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function validate(Param $param, ServerRequestInterface $request): bool
throw new Annotation("compare param: {$this->paramName} require in SmallThanColumn rule ,but not define in any controller annotation");
}
$compare = $list[$this->paramName]->parsedValue();
if($itemData > $compare){
if($itemData >= $compare){
return false;
}else{
return true;
Expand Down
32 changes: 32 additions & 0 deletions tests/ControllerExample/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EasySwoole\HttpAnnotation\Document\Document;
use EasySwoole\HttpAnnotation\Enum\HttpMethod;
use EasySwoole\HttpAnnotation\Enum\ParamFrom;
use EasySwoole\HttpAnnotation\Validator\BigThanColumn;
use EasySwoole\HttpAnnotation\Validator\Integer;
use EasySwoole\HttpAnnotation\Validator\IsUrl;
use EasySwoole\HttpAnnotation\Validator\MaxLength;
Expand All @@ -19,6 +20,7 @@
use EasySwoole\HttpAnnotation\Validator\OptionalIfParamMiss;
use EasySwoole\HttpAnnotation\Validator\OptionalIfParamSet;
use EasySwoole\HttpAnnotation\Validator\Required;
use EasySwoole\HttpAnnotation\Validator\SmallThanColumn;

class Index extends Base
{
Expand Down Expand Up @@ -169,4 +171,34 @@ function testArray(array $data)
{
$this->writeJson(Status::CODE_OK,$data);
}

#[Api(
apiName: 'compare',
requestParam: [
new Param(
name: "a",
validate: [
new Integer(),
new BigThanColumn('b')
]
),
new Param(
name: "b",
validate: [
new Integer()
]
),
new Param(
name: 'c',
validate: [
new Integer(),
new SmallThanColumn('b')
]
)
]
)]
function compare(array $data)
{
$this->writeJson(Status::CODE_OK,$data);
}
}

0 comments on commit b9a04e0

Please sign in to comment.