变更
This commit is contained in:
+4
-3
@@ -28,7 +28,7 @@ abstract class BaseValidator
|
||||
/**
|
||||
* @param $model
|
||||
*/
|
||||
public function setModel($model)
|
||||
public function setModel($model): void
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
@@ -55,9 +55,9 @@ abstract class BaseValidator
|
||||
/**
|
||||
* @param $config
|
||||
*/
|
||||
private function regConfig($config)
|
||||
private function regConfig($config): void
|
||||
{
|
||||
if (empty($config) || !is_array($config)) {
|
||||
if (count($config) < 1) {
|
||||
return;
|
||||
}
|
||||
foreach ($config as $key => $val) {
|
||||
@@ -93,6 +93,7 @@ abstract class BaseValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $message
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
+8
-14
@@ -163,18 +163,10 @@ class Validator extends BaseValidator
|
||||
* @throws Exception
|
||||
* ['maxLength'=>150, 'required', 'minLength' => 100]
|
||||
*/
|
||||
public function createRule($field, $rule, $model, $param)
|
||||
public function createRule($field, $rule, $model, $param): void
|
||||
{
|
||||
$define = ['field' => $field];
|
||||
|
||||
$is_model = is_null($model);
|
||||
foreach ($rule as $key => $val) {
|
||||
if (!$is_model) {
|
||||
if (is_string($val) && method_exists($model, $val)) {
|
||||
$this->validators[] = [$model, $val];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (is_string($key)) {
|
||||
$type = strtolower($key);
|
||||
$define['value'] = $val;
|
||||
@@ -182,12 +174,14 @@ class Validator extends BaseValidator
|
||||
$type = strtolower($val);
|
||||
}
|
||||
if (!isset($this->classMap[$type])) {
|
||||
continue;
|
||||
$this->validators[] = [$model, $val];
|
||||
} else {
|
||||
$merge = array_merge($this->classMap[$type], $define, [
|
||||
'params' => $param,
|
||||
'model' => $model
|
||||
]);
|
||||
$this->validators[] = $merge;
|
||||
}
|
||||
$this->validators[] = array_merge($this->classMap[$type], $define, [
|
||||
'params' => $param,
|
||||
'model' => $model
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user