phrity/util-transformer
Composer 安装命令:
composer require phrity/util-transformer
包简介
Type transformers, normalizers and resolvers.
README 文档
README
Introduction
Type transformers, normalizers and resolvers.
Installation
Install with Composer;
composer require phrity/util-transformer
How to use
All transformers exposes canTransform() and transform() methods.
This allows us to transform data of a certain type to another type. A specific transformer may not be able to transform all types.
$transformer = new BasicTypeConverter(); if ($transformer->canTransform($subject)) { $transformed = transformer->transform($subject); }
As option, a transformer can take a target type specifier as second argument.
$transformer = new BasicTypeConverter(); if ($transformer->canTransform($subject, Type::ARRAY)) { $transformed = transformer->transform($subject, Type::ARRAY); }
Utility resolvers enable stacking multiple transformers and performing other tasks.
$transformer = new RecursionResolver( new FirstMatchResolver([ new EnumConverter(), new ReadableConverter(), new ThrowableConverter(), new StringableConverter(), new BasicTypeConverter(), ]) ); if ($transformer->canTransform($subject, Type::STRING)) { $transformed = transformer->transform($subject, Type::STRING); }
List of transformers in this library
Encoders & Decoders
- Flatten Decoder - Expands array with flattened keys to nested array
- Json Decoder - Decodes JSON string
Type converters
- Basic Type - Support transforming all PHP types to all other types
- DateTime - Transform DateTime classes to string
- Enum - Transform Enums to string
- Json Serializable - Transform JSON serializable objects
- Readable - Transform booleans and null to readable strings
- Reversed Readable - Transform some strings to boolean and null
- Stringable - Transform stringable objects to string
- Throwable - Transform throwable to object, array or string
Utility resolvers
- Chained - Collection of transformers that will send output from one into next one
- First Match - Collection of transformers that will use first compatible transformer for transformation
- Recursion - Will apply transformer recursively
- String - Fold anything to a string
Wrappers
- Symfony Normalizer - Wrap class implementing Symfony
NormalizerInterface
Versions
| Version | PHP | |
|---|---|---|
1.3 |
^8.1 |
Transformer: DateTime, Resolver: Chained, String |
1.2 |
^8.1 |
Additional transformers |
1.1 |
^8.1 |
Additional transformers |
1.0 |
^8.1 |
Initial version |
phrity/util-transformer 适用场景与选型建议
phrity/util-transformer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99.32k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「type」 「resolver」 「transformer」 「normalizer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phrity/util-transformer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phrity/util-transformer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phrity/util-transformer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle providing fields for image upload with jquery upload and image cropping with jcrop for symfony2
Serializer transformers outputting valid API responses in JSON, JSON API and HAL+JSON API formats.
Symfony 2 & 3 JSON API Transformer Package
A simple Symfony bundle that adds boolean form field type.
A PHP Abstract Enum Class
resolve openapi keywords
统计信息
- 总下载量: 99.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-28
