type-lang/mapper

将变量类型映射到其他类型的库

dev-master / 1.0.x-dev 2024-09-09 18:17 UTC

This package is auto-updated.

Last update: 2024-09-09 18:17:23 UTC


README

PHP 8.1+ Latest Stable Version Latest Unstable Version License MIT

你见过的最好的PHP映射器 =)

  1. 你可以在以下链接中看到一些示例
  2. 完整文档正在制作中...

安装

Mapper包作为Composer仓库提供,可以在项目根目录中使用以下命令进行安装

composer require type-lang/mapper

快速入门

class ExampleObject
{
    public function __construct(
        public readonly string $name,
    ) {}
}

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

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

$denormalized = $mapper->denormalize($normalized, ExampleObject::class);
// Expected Result:
// ExampleObject {#14
//   +name: "Example"
// }