-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08fb141
commit 2e6f57f
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace EasySwoole\HttpAnnotation\Validator; | ||
|
||
use EasySwoole\HttpAnnotation\Attributes\Param; | ||
use EasySwoole\HttpAnnotation\Exception\Annotation; | ||
use EasySwoole\HttpAnnotation\Validator\AbstractInterface\AbstractValidator; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
class BigThanColumn extends AbstractValidator | ||
{ | ||
|
||
function __construct(public string $paramName,?string $errorMsg = null) | ||
{ | ||
if(empty($errorMsg)){ | ||
$errorMsg = "{#name} value must big than {$paramName} value"; | ||
} | ||
$this->errorMsg($errorMsg); | ||
} | ||
|
||
protected function validate(Param $param, ServerRequestInterface $request): bool | ||
{ | ||
$itemData = $param->parsedValue(); | ||
$list = $this->allCheckParams(); | ||
if(!isset($list[$this->paramName])){ | ||
throw new Annotation("compare param: {$this->paramName} require in BigThanColumn rule ,but not define in any controller annotation"); | ||
} | ||
$compare = $list[$this->paramName]->parsedValue(); | ||
if($itemData > $compare){ | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
function ruleName(): string | ||
{ | ||
return 'BigThanColumn'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace EasySwoole\HttpAnnotation\Validator; | ||
|
||
use EasySwoole\HttpAnnotation\Attributes\Param; | ||
use EasySwoole\HttpAnnotation\Exception\Annotation; | ||
use EasySwoole\HttpAnnotation\Validator\AbstractInterface\AbstractValidator; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
class SmallThanColumn extends AbstractValidator | ||
{ | ||
|
||
function __construct(public string $paramName,?string $errorMsg = null) | ||
{ | ||
if(empty($errorMsg)){ | ||
$errorMsg = "{#name} value must small than {$paramName} value"; | ||
} | ||
$this->errorMsg($errorMsg); | ||
} | ||
|
||
protected function validate(Param $param, ServerRequestInterface $request): bool | ||
{ | ||
$itemData = $param->parsedValue(); | ||
$list = $this->allCheckParams(); | ||
if(!isset($list[$this->paramName])){ | ||
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){ | ||
return false; | ||
}else{ | ||
return true; | ||
} | ||
} | ||
|
||
function ruleName(): string | ||
{ | ||
return 'SmallThanColumn'; | ||
} | ||
} |