承接 twindigital/deserializer 相关项目开发

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

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

twindigital/deserializer

Composer 安装命令:

composer require twindigital/deserializer

包简介

README 文档

README

Build Status Coverage Status Infection Minimum PhpStan Level Scrutinizer Code Quality Maintainability Latest Stable Version License

Implements Latest Stable Version License

Transforms serialized data into objects.

Installation

Install with composer require stratadox/deserializer

What is this?

An object that Deserializes can convert serialized data into objects.

The serialized input data is expected to have the form of an array, either numeric or associative. This way, one can easily convert both the results of sql queries and decoded json, as well as session data and other sources.

How to use this?

To write the contents of an associative array to an object, one can use:

<?php
use Stratadox\Deserializer\ObjectDeserializer;

$deserialize = ObjectDeserializer::forThe(Foo::class);
$foo = $deserialize->from([
    'bar' => 'Bar.',
    'baz' => 'BAZ!',
]);

assert($foo instanceof Foo);
assert('Bar.' === $foo->bar);
assert('BAZ!' === $foo->getBaz());

For writing the contents of a numerically indexed array into a collection object, use:

<?php
use Stratadox\Deserializer\CollectionDeserializer;

$deserialize = CollectionDeserializer::forImmutable(Numbers::class);
$numbers = $deserialize->from([10, 11, 12]);

assert($numbers instanceof Numbers);
assert(count($numbers) === 3);
assert($numbers[0] === 10);
assert($numbers[1] === 11);
assert($numbers[2] === 12);

Or

<?php
use Stratadox\Deserializer\CollectionDeserializer;

$deserialize = CollectionDeserializer::forMutable(ArrayObject::class);
$numbers = $deserialize->from([10, 11, 12]);

assert($numbers instanceof ArrayObject);
assert(count($numbers) === 3);
assert($numbers[0] === 10);
assert($numbers[1] === 11);
assert($numbers[2] === 12);

In cases where no deserialization is needed, but a Deserializer is expected, one can use the ArrayDeserializer:

<?php
use Stratadox\Deserializer\ArrayDeserializer;

$deserialize = ArrayDeserializer::make();
$input = ['foo', 'bar'];
$output = $deserialize->from($input);

assert($input === $output);

What else can it do?

By default, the collection deserializer uses a CollectionHydrator and the object deserializer uses an ObjectHydrator for simple objects, or a ReflectiveHydrator when inheritance is involved.

This default behaviour can be changed by injecting custom (potentially decorated) hydrators and instantiators:

<?php
use Stratadox\Deserializer\ObjectDeserializer;
use Stratadox\Instantiator\Instantiator;
use Stratadox\Hydrator\ObjectHydrator;

$deserialize = ObjectDeserializer::using(
    Instantiator::forThe(Foo::class),
    ObjectHydrator::default()
);

In some cases, the input can vary in such a way that a different deserializer is required for different types of data.

For instance, when the input data represents an inheritance structure:

<?php
use Stratadox\Deserializer\ForDataSets;
use Stratadox\Deserializer\Condition\HaveTheDiscriminatorValue;
use Stratadox\Deserializer\ObjectDeserializer;
use Stratadox\Deserializer\OneOfThese;

$deserialize = OneOfThese::deserializers(
    ForDataSets::that(
        HaveTheDiscriminatorValue::of('type', 'A'), 
        ObjectDeserializer::forThe(ChildA::class)
    ),
    ForDataSets::that(
        HaveTheDiscriminatorValue::of('type', 'B'), 
        ObjectDeserializer::forThe(ChildB::class)
    )
);

$a = $deserialize->from([
    'type' => 'A',
    'property' => 'value',
]);
$b = $deserialize->from([
    'type' => 'B',
    'attribute' => 'different value',
]);
assert($a instanceof ChildA);
assert($b instanceof ChildB);

These features can be combined into more advanced deserialization structures, such as conditionally applied deserializers that are configured with mapped hydrators.

twindigital/deserializer 适用场景与选型建议

twindigital/deserializer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 115 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 twindigital/deserializer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 twindigital/deserializer 我们能提供哪些服务?
定制开发 / 二次开发

基于 twindigital/deserializer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-14