diff --git a/BaseValidator.php b/BaseValidator.php index e83015b..6adb734 100644 --- a/BaseValidator.php +++ b/BaseValidator.php @@ -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 */ diff --git a/Validator.php b/Validator.php index c3343e1..e8b8027 100644 --- a/Validator.php +++ b/Validator.php @@ -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 - ]); } }