jijoel/sanitization-filters 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jijoel/sanitization-filters

Composer 安装命令:

composer require jijoel/sanitization-filters

包简介

Data sanitizer filters for use with waavi/sanitizer

README 文档

README

This is a collection of custom sanitization filters to be used in conjunction with Waavi/Sanitizer.

Example

Given a data array with the following format:

$data = [
    'first_name'    =>  'john',
    'last_name'     =>  '<strong>DOE</strong>',
    'email'         =>  '  JOHn@DoE.com',
    'birthdate'     =>  '06/25/1980',
    'jsonVar'       =>  '{"name":"value"}',
];

We can easily format it using our Sanitizer and the some of Sanitizer's default filters:

use \Waavi\Sanitizer\Sanitizer;

$filters = [
    'first_name'    =>  'trim|escape|capitalize',
    'last_name'     =>  'trim|escape|capitalize',
    'email'         =>  'trim|escape|lowercase',
    'birthdate'     =>  'trim|format_date:m/d/Y, Y-m-d',
    'jsonVar'       =>  'cast:array',
];

$sanitizer  = new Sanitizer($data, $filters);
var_dump($sanitizer->sanitize());

Which will yield:

[
    'first_name'    =>  'John',
    'last_name'     =>  'Doe',
    'email'         =>  'john@doe.com',
    'birthdate'     =>  '1980-06-25',
    'jsonVar'       =>  '["name" => "value"]',
];

Available Filters

Filter Description
alpha Alphabetic characters only (a-z)
address Street Addresses
country Capitalize country name (or abbreviation)
date Date values
limit Trims the input at a given limit
lower Converts the given string to all lowercase
money Sets the given string to two decimal places
name Converts the string to a Proper Name (eg, Foo O'Bar)
number Returns the numeric part of the given string
phone A US Telephone number
proper Converts the given string to Proper (Title) Case
state Capitalize state name (or abbreviation)
strip Remove some problematic characters from input. These include: ' ? ; -- / &
title-case Converts the given string to Title Case
upper Converts the given string to all uppercase
zip Converts to a US zip code

Installation

Install with composer:

composer require jijoel/sanitization-filters

We also include a Laravel service provider, via auto-discovery. For versions of Laravel prior to 5.5, add it to your providers array in config/app.php:

'providers' => [
    ...
    Waavi\Sanitizer\Laravel\SanitizerServiceProvider::class,
    Jijoel\Sanitizer\Laravel\SanitizerServiceProvider::class,
];

Usage

It's recommended to sanitize your data in a FormRequest object before applying rules. The Waavi/Sanitizer package includes a SanitizesInput trait, which handles this automatically for you.

use Waavi\Sanitizer\Laravel\SanitizesInput;

class MyFormRequest extends FormRequest
{
    use SanitizesInput;

    public function filters()
    {
        return [
            'name' => 'trim|escape|name',
            'email' => 'trim|escape|lower',
        ];
    }

    public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'required|email',
        ];
    }

Please note that at this time, in order for this to work, the Sanitizer facade must exist.

jijoel/sanitization-filters 适用场景与选型建议

jijoel/sanitization-filters 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.85k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 06 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「input」 「laravel」 「sanitation」 「input filter」 「input sanitation」 「input sanitizer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jijoel/sanitization-filters 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jijoel/sanitization-filters 我们能提供哪些服务?
定制开发 / 二次开发

基于 jijoel/sanitization-filters 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-19