承接 ayeo/pinkman 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ayeo/pinkman

最新稳定版本:0.1.1

Composer 安装命令:

composer require ayeo/pinkman

包简介

Simple serialization/deserialization util

README 文档

README

Build Status Coverage Software License

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

统计信息

  • 总下载量: 1.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-26