| 過濾器 | 說明 | 配置示例 |
| --- | --- | --- |
| `abs` | 返回絕對值 | `['field', 'int', 'filter' => 'abs'],` |
| `integer` | 過濾非法字符并轉換為`int`類型**支持數組** | `['userId', 'number', 'filter' => 'int'],` |
| `boolean` | 轉換為`bool`[關于bool值](https://github.com/inhere/php-validate#about-bool-value) | `['argee', 'bool']` |
| `float` | 過濾非法字符,保留`float`格式的數據 | `['price', 'float', 'filter' => 'float'],` |
| `string` | 過濾非法字符并轉換為`string`類型 | `['userId', 'number', 'filter' => 'string'],` |
| `trim` | 去除首尾空白字符,支持數組。 | `['username', 'min', 4, 'filter' => 'trim'],` |
| `nl2br` | 轉換`\n``\r\n``\r`為`<br/>` | `['content', 'string', 'filter' => 'nl2br'],` |
| `lowercase` | 字符串轉換為小寫 | `['description', 'string', 'filter' => 'lowercase'],` |
| `uppercase` | 字符串轉換為大寫 | `['title', 'string', 'filter' => 'uppercase'],` |
| `snakeCase` | 字符串轉換為蛇形風格 | `['title', 'string', 'filter' => 'snakeCase'],` |
| `camelCase` | 字符串轉換為駝峰風格 | `['title', 'string', 'filter' => 'camelCase'],` |
| `strToTime` | 字符串日期轉換時間戳 | `['pulishedAt', 'number', 'filter' => 'strToTime'],` |
| `url` | URL 過濾,移除所有不符合 URL 的字符 | `['field', 'url', 'filter' => 'url'],` |
| `str2array` | 字符串轉數組`'tag0,tag1' -> ['tag0', 'tag1']` | `['tags', 'strList', 'filter' => 'str2array'],` |
| `unique` | 去除數組中的重復值(by`array_unique()`) | `['tagIds', 'intList', 'filter' => 'unique'],` |
| `email` | email 過濾,移除所有不符合 email 的字符 | `['field', 'email', 'filter' => 'email'],` |
| `encoded` | 去除 URL 編碼不需要的字符,與`urlencode()`函數很類似 | `['imgUrl', 'url', 'filter' => 'encoded'],` |
| `clearSpace` | 清理空格 | `['title', 'string', 'filter' => 'clearSpace'],` |
| `clearNewline` | 清理換行符 | `['title', 'string', 'filter' => 'clearNewline'],` |
| `stripTags` | 相當于使用`strip_tags()` | `['content', 'string', 'filter' => 'clearTags'],` |
| `escape` | 相當于使用`htmlspecialchars()`轉義數據 | `['content', 'string', 'filter' => 'escape'],` |
| `quotes` | 應用`addslashes()`轉義數據 | `['content', 'string', 'filter' => 'quotes'],` |
## 注釋用法
~~~
use ESD\Plugins\Validate\Annotation\Filter;
use ESD\Plugins\Validate\Annotation\Validated;
//ValidationTrait
class TestForm{
/**
* @Filter(default="1")
* @Validated(integer=true, required=true, email=true)
* @var int
*/
public $page = 0;
public $test = 0;
}
~~~
- 前言
- 捐贈ESD項目
- 使用篇-通用
- 環境
- 安裝
- 規范
- 壓力測試
- 配置
- 如何設置YML配置
- server配置
- 端口配置
- 項目結構
- 事件派發
- 日志
- 注解
- DI容器
- 自定義進程
- 并發及協程池
- Console插件
- Scheduled插件
- Redis插件
- AOP插件
- Saber插件
- Mysql插件
- mysql事務
- Actuator插件
- Whoops插件
- Cache插件
- PHPUnit插件
- Security插件
- Session插件
- EasyRoute插件
- http路由
- ProcessRpc插件
- AutoReload插件
- AnnotationsScan插件
- Tracing-plugin插件
- MQTT插件
- Pack插件
- AMQP插件
- Validate插件
- Uid插件
- Topic插件
- Blade插件
- CsvReader插件
- hashed-wheel-timer-plugin插件
- 使用篇-HTTP
- 路由
- 靜態文件
- 路由定義
- 修飾方法
- 路由分組
- 資源路由
- 端口作用域
- 異常處理
- 跨域請求
- 路由緩存
- 控制器
- 控制器初始化
- 前置操作
- 跳轉和重定向
- 異常處理
- 請求
- 請求對象
- 請求信息
- request消息
- response消息
- stream消息
- url接口
- 驗證器
- 內置驗證器
- 內置過濾器
- 使用篇-WS
- 如何使用
- 路由
- 使用篇-TCP
- 插件篇-PluginSystem
- 微服務篇-ESDCloud
- CircuitBreaker插件
- SaberCloud插件
- 分布式鏈路追蹤系統
- Consul插件