Skip to content

The best PHP mapper (hydrator/serializer) you've ever seen!

License

Notifications You must be signed in to change notification settings

php-type-language/mapper

Repository files navigation


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