ayeo/pinkman
Composer 安装命令:
composer require ayeo/pinkman
包简介
Simple serialization/deserialization util
README 文档
README
Notice: Pinkman is still not at stable stage yet. Use carefully.
Pinkman is super happy to convert any object to an array for you. It also here to reconsistute the object from pure array data. At my company we happily use Pinkman to help us store our aggregates into the database. In case you struggle with CQRS approachat your side you may find him usefull as well. Think of Pinkman as of your personal laboratory assistant. He can't wait to help you rule the world tonignt.
Motivation
Build-in php serialize/unserialize functions works fine until you are not about to change your objects. Then it becomes impossibne to unserialize prevoisly serialized object. I have found few similar tools on github but wasn't happy with any mainly because of heavy config.
Install
composer require ayeo/pinkman:0.1.0
Core features
- working with privete/proteced properties
- handling nested objects
- handling recurrent nesting
- handling nested arrays/collectoins
The simplest possible scenario example
Serialization
Consider the simple flat object to get the point:
class Address { private $street; private $buildingNumber; private $apartamentNumber; private $postalCode; private $town; public function __construct( string $street, string $buildingNumber, string $apartamentNumver, string $postalCode, string $town, string $countryCode ) { //... } }
Converting to an array is straitforward
use Ayeo/Pinkman/Pinkaman; $address = new Address('Thomas Edisson Av', '34a', '11', 'NG10-32Q', 'Nottingham', 'UK'); $pinkman = new Pinkman() $pureData = $pinkman->distill($address);
Data array looks like this:
$pureData = [ 'street' => 'Thomas Edisson Av', 'buildingNumber' => '34a', 'apartamentNumber' => '11', 'postalCode' => 'NG10-34Q', 'town' => 'Nottingham', 'countryCode' => 'UK' ];
It is nothing more than mapping object structure to an array. But is start shinning with more complex structures.
Deserialization
As you have probably noticed the output data is an array consisting of raw data. To reconstitute living object you need to provide adequate config. In our simple scenario looks like this:
$config = [ 'class' => Address::class ]; $object = $pinkman->hydrate($pureData, $config);
More elaborate and complex examples are comming your way
ayeo/pinkman 适用场景与选型建议
ayeo/pinkman 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.99k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「serialize」 「serializer」 「deserializer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ayeo/pinkman 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ayeo/pinkman 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ayeo/pinkman 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LazyPDO is a set of wrappers over PHP's standard PDO and PDOStatement classes. It enables lazy loading, serialization and decoration.
Bridge between JMS Serializer Bundle and Superdesk Web Publisher.
Transform data structures
De/normalize business objects without tightly coupling them to your normalization format
Lightweight PHP library that allows exchanging binary data with Qt programs (QDataStream)
Deserialize a JsonApi response
统计信息
- 总下载量: 2.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-26