type-lang/mapper

Library for mapping variable types to other types

dev-master / 1.0.x-dev 2024-07-03 19:15 UTC

This package is auto-updated.

Last update: 2024-07-03 19:16:03 UTC


README

PHP 8.1+ Latest Stable Version Latest Unstable Version License MIT

The best PHP mapper you've ever seen =)

  1. You can see some examples here
  2. 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

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"
// }