承接 peeyush-budhia/sanitizer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

peeyush-budhia/sanitizer

Composer 安装命令:

composer require peeyush-budhia/sanitizer

包简介

Sanitization library for PHP and the Laravel framework.

README 文档

README

PHP Version LICENSE

Latest Version on Packagist Total Downloads

Build Status

Sanitization library for PHP and the Laravel framework.

Installation

You can install the package via composer:

composer require peeyush-budhia/sanitizer

Core PHP Usage

use Peeyush\Sanitizer\Sanitizer;

$data = [
    'name' => ' peeyush ',
    'birth_date' => '1987-09-10',
    'email' => 'Peeyush.Budhia@Gmail.CoM',
    'phone' => '(000)-000-00-00',
    'json' => '{"name":"Peeyush"}',
];

$filters = [
    'name' => 'trim|capitalize',
    'birth_date' => 'trim|format_date:"Y-m-d","F j, Y"',
    'email' => ['trim', 'lowercase'],
    'phone' => 'digit'
    'json' => 'cast:array',
];

$sanitizer = new Sanitizer($data, $filters);

var_dump($sanitizer);

Will return:

[
    'name' => 'Peeyush',
    'birth_date' => 'September 10, 1987',
    'email' => 'peeyush.budhia@gmail.com',
    'phone' => '0000000000'
    'json' => ['name' => 'Peeyush'],
];

Laravel Usage

  • Register the provider and update the alias of Sanitizer in config/app.php as under:
'providers' => [
        /*
         * Package Service Providers...
         */
        \Peeyush\Sanitizer\SanitizerServiceProvider::class,
    ]
'aliases' => [
        /*
         * Package aliases...
         */
        'Sanitizer' => \Peeyush\Sanitizer\Facade\SanitizerFacade::class,
    ],
  • Now Publish request.stub and tests directory. To publish, run the following command on terminal, in the document root of the application:
php artisan vendor:publish --provider="Peeyush\Sanitizer\SanitizerServiceProvider"
After the above process you can use Sanitizer as follows
  • Use the Sanitizer through the Facade:
$data = Sanitizer::make($data, $filters)->sanitize();
  • Use SanitizeInput trait to Sanitize input in your FormRequests. Please note you need to add filters method which returns the filters you want to apply to the input.
namespace App\Http\Requests;

use Peeyush\Sanitizer\SanitizeInput;

class ExampleRequest extends Request
{
    use SanitizeInput;
    
    public function filters()
    {
        return [
            'name' => 'trim|capitalize',
        ];
    }
}
  • To auto generate the Request file run the following command on terminal, in the document root of the application:
php artisan make:Request ExampleRequest

Available Filters

Filter Description
trim Trims a string
escape Escapes HTML and other special characters
lowercase Converts a string to lowercase
uppercase Converts a string to UPPERCASE
capitalize Converts a string to Title Case
cast Casts a variable into the given type. Options are: int, float, string, bool, object, array and Laravel Collection collection
format_date Converts the date format. It takes two arguments, first date's given format second date's target format
strip_tags Strip HTML and PHP tags
digit Get only digit characters from a string

Custom Filters

  • Use Closure or Class that implements Peeyush\Sanitizer\Contracts\Filter interface:
class RemoveStringFilter implements \Peeyush\Sanitizer\Contracts\Filter
{
    public function apply($value, array $options)
    {
        return str_replace($options, '', $value);
    }
}

$filters = [
    'remove_strings' => RemoveStringsFilter::class,
];

$sanitize = new Sanitizer($data, $filters)

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固