Skip to content

Commit

Permalink
提交
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjincheng committed May 17, 2019
1 parent 275aea2 commit dff195e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Validate/Annotation/Validated.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ class Validated extends Annotation
* @var bool
*/
public $md5 = false;
/**
* 验证大小范围, 可以支持验证 int, string, array 数据类型,需要设置min,max
* @var bool
*/
public $between = false;
/**
* 长度验证( 跟 size差不多, 但只能验证 string, array 的长度,需要设置min,max
* @var bool
*/
public $length = false;
/**
* 验证是否是 sha1 格式的字符串
* @var bool
Expand Down Expand Up @@ -303,11 +313,18 @@ class Validated extends Annotation

public function build($name)
{
$noMinMax = false;
if ($this->string || $this->integer || $this->number || $this->between || $this->length) {
$noMinMax = true;
}
$result = [];
foreach ($this as $key => $value) {
if ($key == "scene") {
continue;
}
if ($noMinMax && ($key == "min" || $key == "max")) {
continue;
}
$one = [$name];
if ($value === true) {
$one[] = $key;
Expand All @@ -316,6 +333,14 @@ public function build($name)
$one[] = $value;
}
if (count($one) > 1) {
if ($key == "string" || $key == "integer" || $key == "number" || $key == "between" || $key == "length") {
if ($this->min != null) {
$one["min"] = $this->min;
}
if ($this->max != null) {
$one["max"] = $this->max;
}
}
if (!empty($this->scene)) {
$one["on"] = $this->scene;
}
Expand Down

0 comments on commit dff195e

Please sign in to comment.