isStatic()) { $this->success = false; $this->error = json_encode($attribute).'方法不存在'; return false; } if (is_array($v[1])) { foreach ($v[1] as $key => $val) { if (!call_user_func_array([self::class,$v[0]],[$val,$v[2]])) { $this->success = false; $this->error = isset($v[3]) && isset($v[3][$key]) ? $v[3][$key] : false; return false; } } } else { if (!call_user_func_array([self::class,$v[0]],[$v[1],$v[2]])) { $this->success = false; $this->error = isset($v[3]) ? $v[3] : false; return false; } } $this->success = true; $this->error = null; return true; } } /** * 验证字符串 * @param $value * @param $attribute * @return bool */ public static function string ($value, $attribute) { $valid = new StringValidator($attribute); return $valid->validate($value,$error); } /** * 验证数字 * @param $value * @param $attribute * @return bool */ public static function number ($value, $attribute) { $valid = new NumberValidator($attribute); return $valid->validate($value, $error); } /** * 验证邮箱 * @param $value * @return bool */ public static function email ($value, $attribute = []) { $valid = new EmailValidator(); return $valid->validate($value, $error); } /** * 验证手机号 * @param $value * @return bool */ public static function phone ($value, $attribute = []) { $chars = "/^1[3-9]\d{9}$/"; if (preg_match($chars, $value)){ return true; }else{ return false; } } /** * 验证单选 * @param $value * @param $attribute * @return bool */ public static function radio ($value, $attribute) { if (in_array($value,$attribute)) { return true; }else { return false; } } }