waughj/verified-arguments
Composer 安装命令:
composer require waughj/verified-arguments
包简介
Class for generating special type of associative array/map with fallback default values, validity tests, and sanitizers.
README 文档
README
Class for generating special type of associative array/map with fallback default values, validity tests, and sanitizers.
Use
Takes in associative array of custom values, associative array of default values, and boolean determining whether a new value can be set without a default set.
Default values are fallbacks for keys whose values are not custom-set. If neither a default nor custom value is set for a key, trying to get the value of that key returns null. The custom value is only set if it follows the tests and types specified for that default. Tests can be any callable and types must be strings representing the type name. Tests and types can be either singular or lists. A custom-set value must pass all tests in a list and must be at least 1 of the types in a list. Otherwise, the set value with fallback to the default value or to null if no default value is given.
Defaults also have sanitizer, which will be applied to any custom-set values before set. Sanitizers can be any callable and can be singular or an array of callables, which will all be applied to the value in the order given. ( The 2nd sanitizer will sanitize the output of the 1st sanitizer, the 3rd the 2nd, & so on ).
Example
use WaughJ\VerifiedArguments;
$defaults =
[
"name" => [ "value" => "Anonymous", "type" => "string", "sanitizer" => "strtoupper" ],
"age" => [ "type" => "integer" ],
"birthday" => [ "type" => \DateTime::class ]
];
$values = [ "name" => "Jaimeson", "age" => "old", "city" => "SeaTac" ];
$args = new VerifiedArguments( $values, $defaults );
echo( $args->get( "name" ) ); // Will print "JAIMESON".
echo( $args->get( "age" ) ); // Will print null.
echo( $args->get( "city" ) ); // Will print "SeaTac".
Changelog
1.0.0
- Implement custom tests and sanitizers.
- Add flag for blocking custom values without defaults set.
0.6.0
- Add ability to get list from object
0.5.0
- 1st beta.
waughj/verified-arguments 适用场景与选型建议
waughj/verified-arguments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.5k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「array」 「tests」 「arguments」 「sanitizers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 waughj/verified-arguments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 waughj/verified-arguments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 waughj/verified-arguments 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Finally a sane way to register available commands and arguments and match your command line in PHP.
A cli tool which generates unit tests.
Full featured package for managing command-line applications.
Swoole server process management
Laravel tool benchmark
统计信息
- 总下载量: 1.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2018-10-24