Skip to content

Commit b9a04e0

Browse files
committed
新增SmallThanColumn 和BigThanColumn规则
1 parent 2e6f57f commit b9a04e0

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/Validator/SmallThanColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function validate(Param $param, ServerRequestInterface $request): bool
2626
throw new Annotation("compare param: {$this->paramName} require in SmallThanColumn rule ,but not define in any controller annotation");
2727
}
2828
$compare = $list[$this->paramName]->parsedValue();
29-
if($itemData > $compare){
29+
if($itemData >= $compare){
3030
return false;
3131
}else{
3232
return true;

tests/ControllerExample/Index.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use EasySwoole\HttpAnnotation\Document\Document;
1010
use EasySwoole\HttpAnnotation\Enum\HttpMethod;
1111
use EasySwoole\HttpAnnotation\Enum\ParamFrom;
12+
use EasySwoole\HttpAnnotation\Validator\BigThanColumn;
1213
use EasySwoole\HttpAnnotation\Validator\Integer;
1314
use EasySwoole\HttpAnnotation\Validator\IsUrl;
1415
use EasySwoole\HttpAnnotation\Validator\MaxLength;
@@ -19,6 +20,7 @@
1920
use EasySwoole\HttpAnnotation\Validator\OptionalIfParamMiss;
2021
use EasySwoole\HttpAnnotation\Validator\OptionalIfParamSet;
2122
use EasySwoole\HttpAnnotation\Validator\Required;
23+
use EasySwoole\HttpAnnotation\Validator\SmallThanColumn;
2224

2325
class Index extends Base
2426
{
@@ -169,4 +171,34 @@ function testArray(array $data)
169171
{
170172
$this->writeJson(Status::CODE_OK,$data);
171173
}
174+
175+
#[Api(
176+
apiName: 'compare',
177+
requestParam: [
178+
new Param(
179+
name: "a",
180+
validate: [
181+
new Integer(),
182+
new BigThanColumn('b')
183+
]
184+
),
185+
new Param(
186+
name: "b",
187+
validate: [
188+
new Integer()
189+
]
190+
),
191+
new Param(
192+
name: 'c',
193+
validate: [
194+
new Integer(),
195+
new SmallThanColumn('b')
196+
]
197+
)
198+
]
199+
)]
200+
function compare(array $data)
201+
{
202+
$this->writeJson(Status::CODE_OK,$data);
203+
}
172204
}

0 commit comments

Comments
 (0)