定制 indgy/philter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

indgy/philter

Composer 安装命令:

composer require indgy/philter

包简介

A fluent input sanitiser without dependencies

README 文档

README

Philter Logo

A PHP fluent input sanitiser.

Philter accepts untrusted input, passes it through some filters and returns it back to you. It is not a substitution for validation.

Installation

Copy the src/Philter.php file to your project, or install using composer:

composer require indgy/philter

Getting started

Create a new Philter instance passing in the untrusted input, then combine filters for the untrusted input to pass through and finally call toBool(), toFloat(), toInt() or toString() to get the filtered and now trusted input.

use \Indgy\Philter;

$f = new Philter($unsafe_input);
$str = $f->in(['safe','string','options'])
	->default('safe')
	->toString();

There is also a handy shortcut function to return a new Philter instance:

use function \Indgy\philter;

$str = philter($unsafe_input)
	->in(['safe','string','options'])
	->default('safe')
	->toString();

Available filters

allow(String $chars) - Allow only the characters in $chars

alpha() - Allow only a-z

alphanum() - Allow only a-z and 0-9

ascii() - Allow only ASCII chars (32-127), transliterating where possible

between(Int $min, Int $max) - Allow values between min and max inclusive

contains(String $match) - Allow values containing $match

cut(Int $length) - Cut string to $length

digits() - Allow only 0-9

in(Array $items) - Allow if in $items

max(Int $max) - Allow only if less than or equal to $max

min(Int $min) - Allow only if greater than or equal to $min

numeric() - Allow only if numeric, e.g. currency string

trim() - Trim characters from beginning and end (see also ltrim() and rtrim())

utf8() - Convert to UTF-8 transliterating where possible

Refer to the Reference for more detail on the filters.

Custom filters

Define custom filters using the apply() method with a closure. The closure will be passed the current input value and expects it, or null to be returned.

philter('Here we go.. ')->apply(function($v) {
	// do your thing here
	$v = $v.=  'I was philtered';
	// always return $v or null
	return $v;
})->toString();

Documentation

Refer to the user guide or browse the API .

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固