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