承接 type-lang/mapper 相关项目开发

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

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

type-lang/mapper

Composer 安装命令:

composer require type-lang/mapper

包简介

Library for mapping variable types to other types

README 文档

README

PHP 8.1+ Latest Stable Version Latest Unstable Version License MIT

The best PHP mapper you've ever seen =)

You can see some examples here:

Full documentation in progress...

Installation

Mapper package is available as Composer repository and can be installed using the following command in a root of your project:

composer require type-lang/mapper

Quick Start

use TypeLang\Mapper\Mapping\MapType;

class ExampleObject
{
    public function __construct(
        #[MapType('list<non-empty-string>')]
        public readonly array $names,
    ) {}
}

$mapper = new \TypeLang\Mapper\Mapper();

$result = $mapper->normalize(
    new ExampleObject(['Example'])
);
// Expected Result:
//
// array:1 [
//   "names" => array:1 [
//     0 => "Example"
//   ]
// ]


$result = $mapper->denormalize([
    'names' => ['first', 'second']
], ExampleObject::class);
// Expected Result:
//
// ExampleObject {#324
//   +names: array:2 [
//     0 => "first"
//     1 => "second"
//   ]
// }


$result = $mapper->denormalize([
    'names' => ['first', 'second', ''],
], ExampleObject::class);
// Expected Result:
//
// InvalidFieldTypeValueException: Passed value of field "names" must be of type
//   list<non-empty-string>, but array(3)["first", "second", ""] given at $.names[2]

Benchmarks

Results here like this.

Sample: An object that contains a collection of objects, which contains another collection of objects.

object<ExampleObject>{
    name: string,
    items: list<ExampleObject>
}

The results are sorted by mode time.

Denormalization

Denormalization: For example, conversion from JSON to PHP Object.

benchmark memory min mode rstdev
TypeLangStrictAttributesBench 1.929mb 91.180μs 105.264μs ±6.99%
TypeLangStrictPhpDocBench 2.048mb 98.860μs 108.488μs ±4.40%
TypeLangPhpDocBench 2.050mb 103.380μs 106.407μs ±5.91%
TypeLangAttributesBench 1.930mb 104.490μs 113.736μs ±4.23%
JMSAttributesBench 3.141mb 137.040μs 142.373μs ±6.78%
ValinorBench 2.701mb 227.370μs 252.458μs ±4.59%
SymfonyPHPStanExtractorBench 3.678mb 371.650μs 392.908μs ±2.86%
SymfonyPhpDocExtractorBench 4.027mb 379.740μs 387.303μs ±3.21%

Normalization

Normalization: For example, conversion from PHP Object to JSON.

benchmark memory min mode rstdev
ValinorBench 1.966mb 62.570μs 69.184μs ±3.99%
TypeLangStrictAttributesBench 1.845mb 81.090μs 88.343μs ±6.75%
TypeLangPhpDocBench 1.965mb 81.800μs 90.504μs ±5.99%
TypeLangAttributesBench 1.891mb 85.320μs 89.900μs ±5.15%
TypeLangStrictPhpDocBench 1.967mb 89.920μs 94.865μs ±2.62%
SymfonyPHPStanExtractorBench 2.086mb 93.160μs 100.173μs ±5.41%
SymfonyPhpDocExtractorBench 2.405mb 96.290μs 98.729μs ±4.17%
JMSAttributesBench 3.770mb 131.420μs 150.310μs ±5.85%

type-lang/mapper 适用场景与选型建议

type-lang/mapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.1k 次下载、GitHub Stars 达 35, 最近一次更新时间为 2024 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「serializer」 「mapper」 「transformer」 「hydrator」 「normalizer」 「types」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 type-lang/mapper 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-29