netherphp/input
Composer 安装命令:
composer require netherphp/input
包简介
Input Handling.
关键字:
README 文档
README
An input filtering interface. It allows you to define a set of dynamic filters for input to be run applied just-in-time on your specified data source.
Super simple example:
$input = (new Nether\Input\Filter)
->Email(function($t){ return filter_var($t,FILTER_VALIDATE_EMAIL); });
// ... some time later...
$input->SetDataset($_POST);
if(!$input->Email) {
throw new Exception('valid email address is required.');
}
To pull this off, things like your HTML form field names will need to follow the same rules as properties in PHP (alphanumeric and _ starting with a letter). By default it is case insensitive, so you can send all lowercase from your URL if you want and then reference them in whateverCase YouChoose to use. That can be disabled if you are on a performance powertrip.
You can pass any array or object to the constructor or use SetDataset(). Typical uses would be for _GET and _POST but you could apply it to any named dataset that needs looked at. You can also change datasets at will, keeping any predefined filters intact.
Another Simple Example:
Lets say we want to dump our POST data back into our form because there was some sort of validation error. This is the time where it is very easy to accidentally open yourself up to cross-site scripting problems. Input Filter can take care of that for you though by defining a default filter that all fields which do not have their own special filters for, get run through.
$data = (new Nether\Input\Filter($_POST))
->SetDefaultFunction(function($v){ return htmlspecialchars($v) });
// ... some time later...
<input type="text" name="Username" value="<?php echo $data->Username ?>" />
Creating a new interface.
Wrap any object or array in the OOP interface.
$input = new Nether\Input\Filter($_POST);
Retrieve a value.
Fetch the value from $_POST['myfield'], after running it through any filters we assigned to the field.
$val = $input->MyField
Set a value.
Note, this will not update the original source array. Writing back to the dataset will prompt the copy-on-write, so now you have your own unique dataset and in this example, will not affect the original $_POST['myfield'].
$input->MyField = 'ten';
Set a filter.
You call the field as a method, passing it a callable function with one argument which is the value.
$input->MyField(function($t){
return str_repalce('a','@',$t);
});
Retrieve a filter.
You invoke the object directly, passing it a string that was the name of the field you originally defined the callback on. Here is an example reusing an existing callback on another field.
$input->MyOtherField($input('MyField'));
Installing
Require this package in your composer.json.
require {
"netherphp/input": "~1.0.0"
}
Then install it or update into it.
$ composer install --no-dev
$ composer update --no-dev
Testing
This library uses Codeception for testing. Composer will handle it for you. Install or Update into it.
$ composer install --dev
$ composer update --dev
Then run the tests.
$ php vendor/bin/codecept run unit
$ vendor\bin\codecept run unit
netherphp/input 适用场景与选型建议
netherphp/input 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 335 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「filter」 「input」 「sanitisation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 netherphp/input 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 netherphp/input 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 netherphp/input 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
Widget to add a remaining character counter to text inputs and textareas
Nova searchable filter for belongsTo relationships.
Native (browser) color input field for SilverStripe
Symfony DataGridBundle
Integration bundle for Aura.Input with Aura.Filter
统计信息
- 总下载量: 335
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2015-05-13