改名
This commit is contained in:
+18
-17
@@ -34,7 +34,7 @@ class Validator extends BaseValidator
|
|||||||
'required' => [
|
'required' => [
|
||||||
'class' => 'validator\RequiredValidator',
|
'class' => 'validator\RequiredValidator',
|
||||||
],
|
],
|
||||||
'enum' => [
|
'enum' => [
|
||||||
'class' => 'validator\EnumValidator',
|
'class' => 'validator\EnumValidator',
|
||||||
],
|
],
|
||||||
'unique' => [
|
'unique' => [
|
||||||
@@ -102,8 +102,8 @@ class Validator extends BaseValidator
|
|||||||
'class' => 'validator\LengthValidator',
|
'class' => 'validator\LengthValidator',
|
||||||
'method' => 'default',
|
'method' => 'default',
|
||||||
],
|
],
|
||||||
'round' => [
|
'round' => [
|
||||||
'class' => 'validator\RoundValidator',
|
'class' => 'validator\RoundValidator',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -150,33 +150,29 @@ class Validator extends BaseValidator
|
|||||||
public function createRule($field, $rule, $model, $param)
|
public function createRule($field, $rule, $model, $param)
|
||||||
{
|
{
|
||||||
$define = ['field' => $field];
|
$define = ['field' => $field];
|
||||||
foreach ($rule as $key => $val) {
|
|
||||||
|
|
||||||
if (!is_null($model)) {
|
$is_model = is_null($model);
|
||||||
|
foreach ($rule as $key => $val) {
|
||||||
|
if (!$is_model) {
|
||||||
if (is_string($val) && method_exists($model, $val)) {
|
if (is_string($val) && method_exists($model, $val)) {
|
||||||
$this->validators[] = [$model, $val];
|
$this->validators[] = [$model, $val];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string($key)) {
|
if (is_string($key)) {
|
||||||
$type = strtolower($key);
|
$type = strtolower($key);
|
||||||
$define['value'] = $val;
|
$define['value'] = $val;
|
||||||
} else {
|
} else {
|
||||||
$type = strtolower($val);
|
$type = strtolower($val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->classMap[$type])) {
|
if (!isset($this->classMap[$type])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$constr = array_merge($this->classMap[$type], $define);
|
$constr = array_merge($this->classMap[$type], $define, [
|
||||||
|
'params' => $param,
|
||||||
/** @var BaseValidator $class */
|
'model' => $model
|
||||||
$class = Kiri::createObject($constr);
|
]);
|
||||||
$class->setParams($param);
|
$this->validators[] = $constr;
|
||||||
$class->setModel($model);
|
|
||||||
|
|
||||||
$this->validators[] = $class;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +185,6 @@ class Validator extends BaseValidator
|
|||||||
if (count($this->validators) < 1) {
|
if (count($this->validators) < 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->validators as $val) {
|
foreach ($this->validators as $val) {
|
||||||
if ($this->check($val)) {
|
if ($this->check($val)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -215,7 +210,13 @@ class Validator extends BaseValidator
|
|||||||
if (is_callable($val, true)) {
|
if (is_callable($val, true)) {
|
||||||
return call_user_func($val, $this);
|
return call_user_func($val, $this);
|
||||||
}
|
}
|
||||||
return $val->trigger();
|
|
||||||
|
$class = Kiri::getDi()->get($val['class']);
|
||||||
|
unset($val['class']);
|
||||||
|
|
||||||
|
Kiri::configure($class, $val);
|
||||||
|
|
||||||
|
return $class->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user