yzen.dev/typer
Composer 安装命令:
composer require yzen.dev/typer
包简介
Get property from dynamic instance
README 文档
README
This is a simple helper package that helps make the code cleaner. Often, when working with data from third-party sources, such as website parsing, you need to write hundreds of lines of code to check for a particular property.
Most likely, you write a lot of if or ternary operators, and your code looks something like this:
$user = new User(); $user->id = isset($dynamicArray['id']) ? (int)$dynamicArray['id'] : null; $user->email = isset($dynamicArray['email']) ? (string)$dynamicArray['email'] : null; $user->balance = isset($dynamicArray['balance']) ? (float)$dynamicArray['balance'] : null; $user->blocked = isset($dynamicArray['blocked']) ? ($dynamicArray['blocked'] === 'true' ? true : false) : null;
When using Typer, you don't need to worry about a lot of checks and transformations. Simply wrap the code in the typer method:
$user = new User(); $user->id = Typer::int($dynamicArray, 'id'); $user->email = Typer::string($dynamicArray, 'email'); $user->balance = Typer::float($dynamicArray, 'balance'); $user->blocked = Typer::bool($dynamicArray, 'blocked');
If, in the absence of a parameter, you need to specify a default value other than "null", you can simply pass it as the second argument:
$user->balance = Typer::float($dynamicArray, 'balance', 10.0);
Installation
The package can be installed via composer:
composer require yzen.dev/typer
yzen.dev/typer 适用场景与选型建议
yzen.dev/typer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「array」 「object」 「dynamic」 「getter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yzen.dev/typer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yzen.dev/typer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yzen.dev/typer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Runn Me! Value Objects Library
Laravel SDK mapping data in object
Trait providing methods to set class properties with an array.
Traits to build collections of specific objects
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-18