Validate 有很大概率會被繼承所以這里列出protected方法和屬性
**protected屬性:**
$type = [] -- 自定義驗證類型
$alias = [ '>' => 'gt', '>=' => 'egt', '<' => 'lt', '<=' => 'elt', '=' => 'eq', 'same' => 'eq',] -- 驗證類型別名
$rule = [] -- 當前驗證規則
$message = [] -- 驗證提示信息
$field = [] -- 驗證字段描述
$currentScene="" -- 當前驗證場景
$scene = [] -- 驗證場景定義
$error = [] 或 $error ="" -- 驗證失敗錯誤信息
$batch = false -- 是否批量驗證
$failException = false -- 驗證失敗是否拋出異常
$only = [] -- 場景需要驗證的規則
$remove = [] -- 場景需要移除的驗證規則
$append = [] -- 場景需要追加的驗證規則
$regex = [] -- 驗證正則定義
$db -- Db對象
$lang -- 語言對象
$request -- Request請求對象
$maker = [] --
$typeMsg -- 默認規則提示
```
$typeMsg = [
'require' => ':attribute require',
'must' => ':attribute must',
'number' => ':attribute must be numeric',
'integer' => ':attribute must be integer',
'float' => ':attribute must be float',
'boolean' => ':attribute must be bool',
'email' => ':attribute not a valid email address',
'mobile' => ':attribute not a valid mobile',
'array' => ':attribute must be a array',
'accepted' => ':attribute must be yes,on or 1',
'date' => ':attribute not a valid datetime',
'file' => ':attribute not a valid file',
'image' => ':attribute not a valid image',
'alpha' => ':attribute must be alpha',
'alphaNum' => ':attribute must be alpha-numeric',
'alphaDash' => ':attribute must be alpha-numeric, dash, underscore',
'activeUrl' => ':attribute not a valid domain or ip',
'chs' => ':attribute must be chinese',
'chsAlpha' => ':attribute must be chinese or alpha',
'chsAlphaNum' => ':attribute must be chinese,alpha-numeric',
'chsDash' => ':attribute must be chinese,alpha-numeric,underscore, dash',
'url' => ':attribute not a valid url',
'ip' => ':attribute not a valid ip',
'dateFormat' => ':attribute must be dateFormat of :rule',
'in' => ':attribute must be in :rule',
'notIn' => ':attribute be notin :rule',
'between' => ':attribute must between :1 - :2',
'notBetween' => ':attribute not between :1 - :2',
'length' => 'size of :attribute must be :rule',
'max' => 'max size of :attribute must be :rule',
'min' => 'min size of :attribute must be :rule',
'after' => ':attribute cannot be less than :rule',
'before' => ':attribute cannot exceed :rule',
'expire' => ':attribute not within :rule',
'allowIp' => 'access IP is not allowed',
'denyIp' => 'access IP denied',
'confirm' => ':attribute out of accord with :2',
'different' => ':attribute cannot be same with :2',
'egt' => ':attribute must greater than or equal :rule',
'gt' => ':attribute must greater than :rule',
'elt' => ':attribute must less than or equal :rule',
'lt' => ':attribute must less than :rule',
'eq' => ':attribute must equal :rule',
'unique' => ':attribute has exists',
'regex' => ':attribute not conform to the rules',
'method' => 'invalid Request method',
'token' => 'invalid token',
'fileSize' => 'filesize not match',
'fileExt' => 'extensions to upload is not allowed',
'fileMime' => 'mimetype to upload is not allowed',
];
```
$defaultRegex -- 內置正則驗證規則
```
$defaultRegex = [
'alpha' => '/^[A-Za-z]+$/',
'alphaNum' => '/^[A-Za-z0-9]+$/',
'alphaDash' => '/^[A-Za-z0-9\-\_]+$/',
'chs' => '/^[\x{4e00}-\x{9fa5}]+$/u',
'chsAlpha' => '/^[\x{4e00}-\x{9fa5}a-zA-Z]+$/u',
'chsAlphaNum' => '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9]+$/u',
'chsDash' => '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-]+$/u',
'mobile' => '/^1[3-9]\d{9}$/',
'idCard' => '/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)/',
'zip' => '/\d{6}/',
];
```
$filter -- Filter_var 規則
```
$filter = [
'email' => FILTER_VALIDATE_EMAIL,
'ip' => [FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6],
'integer' => FILTER_VALIDATE_INT,
'url' => FILTER_VALIDATE_URL,
'macAddr' => FILTER_VALIDATE_MAC,
'float' => FILTER_VALIDATE_FLOAT,
];
```
**public方法:**
static maker(Closure $maker):void -- 設置服務注入
setLang(Lang $lang):void -- 設置Lang對象
setDb(Db $db):void -- 設置Db對象
setRequest(Request $request):void -- 設置Request對象
rule($name, $rule = ''):Validate -- 添加字段驗證規則
extend(string $type, callable $callback = null, string $message = null):Validate -- 添加字段驗證規則
setTypeMsg($type, string $msg = null): void -- 設置驗證規則的默認提示信息
message(array $message):Validate -- 設置提示信息
scene(string $name):Validate -- 設置驗證場景
hasScene(string $name): bool -- 判斷是否存在某個驗證場景
batch(bool $batch = true):Validate -- 設置批量驗證
failException(bool $fail = true):Validate -- 設置驗證失敗后是否拋出異常
only(array $fields):Validate -- 指定需要驗證的字段列表
remove($field, $rule = null):Validate -- 移除某個字段的驗證規則
append($field, $rule = null):Validate -- 追加某個字段的驗證規則
check(array $data, array $rules = []): bool -- 數據自動驗證
checkRule($value, $rules): bool -- 根據驗證規則驗證數據
confirm($value, $rule, array $data = [], string $field = ''): bool -- 驗證是否和某個字段的值一致
different($value, $rule, array $data = []): bool -- 驗證是否和某個字段的值是否不同
egt($value, $rule, array $data = []): bool -- 驗證是否大于等于某個值
gt($value, $rule, array $data = []): bool -- 驗證是否大于某個值
elt($value, $rule, array $data = []): bool -- 驗證是否小于等于某個值
lt($value, $rule, array $data = []): bool -- 驗證是否小于某個值
eq($value, $rule): bool -- 驗證是否等于某個值
must($value, $rule = null): bool -- 必須驗證
is($value, string $rule, array $data = []): bool -- 驗證字段值是否為有效格式
token($value, string $rule, array $data): bool -- 驗證表單令牌
activeUrl(string $value, string $rule = 'MX'): bool -- 驗證是否為合格的域名或者IP 支持A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY類型
ip($value, string $rule = 'ipv4'): bool -- 驗證是否有效IP
fileExt($file, $rule): bool -- 驗證上傳文件后綴
fileMime($file, $rule): bool -- 驗證上傳文件類型
fileSize($file, $rule): bool -- 驗證上傳文件大小
image($file, $rule): bool -- 驗證圖片的寬高及類型
dateFormat($value, $rule): bool -- 驗證時間和日期是否符合指定格式
unique($value, $rule, array $data = [], string $field = ''): bool -- 驗證是否唯一
filter($value, $rule): bool -- 使用filter_var方式驗證
requireIf($value, $rule, array $data = []): bool -- 驗證某個字段等于某個值的時候必須
requireCallback($value, $rule, array $data = []): bool -- 通過回調方法驗證某個字段是否必須
requireWith($value, $rule, array $data = []): bool -- 驗證某個字段有值的情況下必須
requireWithout($value, $rule, array $data = []): bool -- 驗證某個字段沒有值的情況下必須
in($value, $rule): bool -- 驗證是否在范圍內
notIn($value, $rule): bool -- 驗證是否不在某個范圍
between($value, $rule): bool -- between驗證數據
notBetween($value, $rule): bool -- 使用notbetween驗證數據
length($value, $rule): bool -- 驗證數據長度
max($value, $rule): bool -- 驗證數據最大長度
min($value, $rule): bool -- 驗證數據最小長度
after($value, $rule, array $data = []): bool -- 驗證日期
before($value, $rule, array $data = []): bool -- 驗證日期
afterWith($value, $rule, array $data = []): bool -- 驗證日期
beforeWith($value, $rule, array $data = []): booll -- 驗證日期
expire($value, $rule): bool -- 驗證有效期
allowIp($value, $rule): bool -- 驗證IP許可
denyIp($value, $rule): bool -- 驗證IP禁用
regex($value, $rule): bool -- 使用正則驗證數據
getError():array|string -- 獲取錯誤信息
__call($method, $args):bool -- 動態方法 直接調用is方法進行驗證
**protected方法:**
checkItem(string $field, $value, $rules, $data, string $title = '', array $msg = []):mixed -- 驗證單個字段規則
getValidateType($key, $rule): array -- 獲取當前驗證類型及規則
getImageType($image):string|false -- 判斷圖像類型
checkExt(File $file, $ext): bool -- 檢測上傳文件后綴
checkSize(File $file, $size): bool -- 檢測上傳文件大小
checkMime(File $file, $mime): bool -- 檢測上傳文件類型
getDataValue(array $data, $key) -- 獲取數據值
getRuleMsg(string $attribute, string $title, string $type, $rule):string|array -- 獲取驗證規則的錯誤提示信息
parseErrorMsg(string $msg, $rule, string $title):string -- 獲取驗證規則的錯誤提示信息
errorMsgIsArray(array $msg, $rule, string $title):array -- 錯誤信息數組處理
getScene(string $scene): void -- 獲取數據驗證的場景
- 空白目錄
- php語法結構
- 安裝與更新
- 開啟調試模式及代碼跟蹤器
- 架構
- 源碼分析
- 應用初始化
- 請求流程
- 中間件源碼分析
- 請求處理源碼分析
- Request源碼分析
- 模板編譯流程
- 路由與請求流程
- 容器
- 獲取目錄位置
- 入口文件
- 多應用模式及URL訪問
- 依賴注入與容器
- 容器屬性及方法
- Container
- App
- facade
- 中間件(middleware)
- 系統服務
- extend 擴展類庫
- 筆記
- 配置
- env配置定義及獲取
- 配置文件的配置獲取
- 單應用模式-(配置)文件目錄結構(默認)
- 多應用模式(配置)文件目錄結構(配置文件)
- 配置文件
- 應用配置:app.php
- 緩存配置: cache.php
- 數據庫配置:database.php
- 路由和URL配置:route.php
- Cookie配置:cookie.php
- Session配置:session.php
- 命令行配置:console.php
- 多語言配置:lang.php
- 日志配置:log.php
- 頁面Trace配置:trace.php
- 磁盤配置: filesystem.php
- 中間件配置:middleware.php
- 視圖配置:view.php
- 改成用yaconf配置
- 事件
- 例子:省略事件類的demo
- 例子2:完整事件類
- 例子3:事件訂閱,監聽多個事件
- 解析
- 路由
- 路由定義
- 路由地址
- 變量規則
- MISS路由
- URL生成
- 閉包支持
- 路由參數
- 路由中間件
- 路由分組
- 資源路由
- 注解路由
- 路由綁定
- 域名路由
- 路由緩存
- 跨域路由
- 控制器
- 控制器定義
- 空控制器、空操作
- 空模塊處理
- RESTFul資源控制器
- 控制器中間件
- 請求對象Request(url參數)
- 請求信息
- 獲取輸入變量($_POST、$_GET等)
- 請求類型的獲取與偽裝
- HTTP頭信息
- 偽靜態
- 參數綁定
- 請求緩存
- 響應對象Response
- 響應輸出
- 響應參數
- 重定向
- 文件下載
- 錯誤頁面的處理辦法
- 應用公共文件common.php
- 模型
- 模型定義及常規屬性
- 模型數據獲取與模型賦值
- 查詢
- 數據集
- 增加
- 修改
- 刪除
- 條件
- 查詢范圍scope
- 獲取器
- 修改器
- 搜索器
- 軟刪除
- 模型事件
- 關聯預載入
- 模型關聯
- 一對一關聯
- 一對多關聯
- 多對多關聯
- 自動時間戳
- 事務
- 數據庫
- 查詢構造器
- 查詢合集
- 子查詢
- 聚合查詢
- 時間查詢
- 視圖查詢(比join簡單)
- 獲取查詢參數
- 快捷方法
- 動態查詢
- 條件查詢
- 打印sql語句
- 增
- 刪
- 改
- 查
- 鏈式操作
- 查詢表達式
- 分頁查詢
- 原生查詢
- JSON字段
- 鏈接數據庫配置
- 分布式數據庫
- 查詢事件
- Db獲取器
- 事務操作
- 存儲過程
- Db數據集
- 數據庫驅動
- 視圖
- 模板
- 模板配置
- 模板位置
- 模板渲染
- 模板變量與賦值(assign)
- 模板輸出替換
- url生成
- 模板詳解
- 內置標簽
- 三元運算
- 變量輸出
- 函數輸出
- Request請求參數
- 模板注釋及原樣輸出
- 模板繼承
- 模板布局
- 原生PHP
- 模板引擎
- 視圖過濾
- 視圖驅動
- 驗證
- 驗證進階之最終版
- 錯誤和日志
- 異常處理
- 日志處理
- 調試
- 調試模式
- Trace調試
- SQL調試
- 變量調試
- 遠程調試
- 雜項
- 緩存
- Session
- Cookie
- 多語言
- 上傳
- 擴展說明
- N+1查詢
- TP類庫
- 擴展類庫
- 數據庫遷移工具
- Workerman
- think助手工具庫
- 驗證碼
- Swoole
- request
- app
- Response
- View
- Validate
- Config
- 命令行
- 助手函數
- 升級指導(功能的添加與刪除說明)
- siyucms
- 開始
- 添加頁面流程
- 列表頁加載流程
- 彈出框
- 基礎控制器
- 基礎模型
- 快速構建
- 表單form構建
- 表格table構建
- MakeBuilder
- 前端組件
- 日期組件
- layer 彈層組件
- Moment.js 日期處理插件
- siyucms模板布局
- 函數即其變量
- 前端頁面
- $.operate.方法
- $.modal.方法:彈出層
- $.common.方法:通用方法
- 被cms重寫的表格options
- 自定義模板
- 搜索框
- 自定義form表單
- 獲取表單搜索參數并組裝為url字符串