daylerees/sanitizer
Composer 安装命令:
composer require daylerees/sanitizer
包简介
README 文档
README
Sanitizer Package
Sanitizers can be used to standardize data to ease validation, or provide data consistency.
Basic Usage
First construct a rules array.
$rules = [
'name' => 'trim',
'email' => 'trim|strtolower'
];
Rules can contain either callable functions, or the name of a sanitizer binding (more later). You can use either a pipe | or an array to specify multiple sanitization rules.
The sanitizer can be executed in the following fashion.
$sanitizer = new Sanitizer;
$sanitizer->sanitize($rules, $data);
Here's a full example.
// Construct rules array.
$rules = [
'name' => 'trim',
'email' => 'trim|strtolower'
];
// Data array to be sanitized.
$data = [
'name' => ' Dayle ',
'email' => ' me@DAYLEREES.com'
];
// Construct a new sanitizer.
$sanitizer = new Sanitizer;
// Execute the sanitizer.
$sanitizer->sanitize($rules, $data);
Here's the content of $data after execution.
[
'name' => 'Dayle',
'email' => 'me@daylerees.com'
]
Using the Laravel facade, the syntax can be made a little cleaner.
Sanitizer::sanitize($rules, $data);
Sanitize a single value like so.
$rules = 'trim|strtolower';
$data = ' Dayle';
Sanitizer::sanitizeValue($rules, $data);
Here is the value returned.
dayle
Custom Sanitization Rules
Sanitizers can be added multiple ways.
Using a Closure.
Sanitizer::register('reverse', function ($field) {
return strrev($field);
});
Using a Callback.
Sanitizer::register('reverse', [new ClassHere, 'method']);
Using a class/method pair.
Sanitizer::register('reverse', 'Namespace\Class\Here@method');
The class will be resolved through an instance of the Illuminate IoC container, if no method is provided then sanitize() is assumed.
Installation
The Sanitizer package can be used stand-alone or with the Laravel Framework.
Stand-alone
First include the sanitizer package.
"daylerees/sanitizer": "dev-master"
Now simply use the Sanitizer class.
use Rees\Sanitizer\Sanitizer;
With Laravel
Include the Service Provider class within the app/config/app.php file.
'providers' => array(
...
'Rees\Sanitizer\SanitizerServiceProvider'
)
Now simply add the facade alias.
'aliases' => array(
...
'Sanitizer' => 'Rees\Sanitizer\Facade'
)
daylerees/sanitizer 适用场景与选型建议
daylerees/sanitizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 127.28k 次下载、GitHub Stars 达 256, 最近一次更新时间为 2014 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 daylerees/sanitizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 daylerees/sanitizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 127.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 257
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-05-22