PHPackages                             type-lang/mapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. type-lang/mapper

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

type-lang/mapper
================

Library for mapping variable types to other types

0.7.2(5mo ago)347.1k↓33.3%2[2 issues](https://github.com/php-type-language/mapper/issues)MITPHPPHP ^8.1CI passing

Since Oct 15Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/php-type-language/mapper)[ Packagist](https://packagist.org/packages/type-lang/mapper)[ RSS](/packages/type-lang-mapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (14)Used By (0)

[ ![](https://github.com/php-type-language/.github/raw/master/assets/dark.png?raw=true)](https://github.com/php-type-language)---

 [![PHP 8.1+](https://camo.githubusercontent.com/49ea5755d6e714dae97ff112b4680c6d2be32b94dbc38d2c5ef662ff315bfa0f/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f6d61707065722f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/mapper) [![Latest Stable Version](https://camo.githubusercontent.com/5c6f0e5ac53b8602b8be3c560ccf55f04c8042d114f0519218292d2d99999707/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f6d61707065722f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/mapper) [![Latest Unstable Version](https://camo.githubusercontent.com/5fe37dc2f61e168ca8050bfc741d6a7fec337679dd620267cdc87e71b9bb162d/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f6d61707065722f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/mapper) [![License MIT](https://camo.githubusercontent.com/046fab88103e1d7884780cdbe37a75bcbb7e6394bde2ee377fb7c50ac0f66b5b/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f6d61707065722f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/php-type-language/mapper/blob/master/LICENSE)

 [![](https://github.com/php-type-language/mapper/workflows/tests/badge.svg)](https://github.com/php-type-language/mapper/actions)

The best PHP mapper you've ever seen =)

You can see some [examples here](/example):

- [01.normalization](/example/01.normalization)
    - [01.object-normalization](/example/01.normalization/01.object-normalization.php)
    - [02.date-normalization](/example/01.normalization/02.date-normalization.php)
    - [03.date-format-normalization](/example/01.normalization/03.date-format-normalization.php)
    - [04.untyped-object-normalization](/example/01.normalization/04.untyped-object-normalization.php)
    - [05.typed-object-normalization](/example/01.normalization/05.typed-object-normalization.php)
    - [06.inherited-types-normalization](/example/01.normalization/06.inherited-types-normalization.php)
    - [07.collection-types-normalization](/example/01.normalization/07.collection-types-normalization.php)
    - [08.object-output-normalization](/example/01.normalization/08.object-output-normalization.php)
- [02.errors](/example/02.errors)
    - [01.custom-type-printer](/example/02.errors/01.custom-type-printer.php)
    - [02.extended-type-printer](/example/02.errors/02.extended-type-printer.php)
    - [03.custom-path-printer](/example/02.errors/03.custom-value-printer.php)
    - [04.custom-value-printer](/example/02.errors/04.custom-path-printer.php)
- [03.types](/example/03.types)
    - [01.type-platforms](/example/03.types/01.type-platforms.php)
    - [02.custom-type](/example/03.types/02.custom-type.php)
    - [03.custom-type-template-arguments](/example/03.types/03.custom-type-template-arguments.php)
    - [04.custom-platform](/example/03.types/04.custom-platform.php)
    - [05.custom-type-callable](/example/03.types/05.custom-type-callable.php)
    - [06.custom-type-psr-container](/example/03.types/06.custom-type-psr-container.php)
- [04.mapping-readers](/example/04.mapping-readers)
    - [01.reflection-mapping.php](/example/04.mapping-readers/01.reflection-mapping.php)
    - [02.attribute-mapping.php](/example/04.mapping-readers/02.attribute-mapping.php)
    - [03.phpdoc-mapping.php](/example/04.mapping-readers/03.phpdoc-mapping.php)
    - [04.array-mapping.php](/example/04.mapping-readers/04.array-mapping.php)
    - [05.php-config-mapping.php](/example/04.mapping-readers/05.php-config-mapping.php)
    - [06.yaml-config-mapping.php](/example/04.mapping-readers/06.yaml-config-mapping.php)
    - [07.neon-config-mapping.php](/example/04.mapping-readers/07.neon-config-mapping.php)
    - [08.inheritance.php](/example/04.mapping-readers/08.inheritance.php)
- [05.mapping-providers](/example/05.mapping-providers)
    - [01.default-provider.php](/example/05.mapping-providers/01.default-provider.php)
    - [02.in-memory-provider.php](/example/05.mapping-providers/02.in-memory-provider.php)
    - [03.psr6-provider.php](/example/05.mapping-providers/03.psr6-provider.php)
    - [04.psr16-provider.php](/example/05.mapping-providers/04.psr16-provider.php)
    - [05.second-level-cache.php](/example/05.mapping-providers/05.second-level-cache.php)
    - [06.inheritance.php](/example/05.mapping-providers/06.inheritance.php)

> Full documentation in progress...

Installation
------------

[](#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
-----------

[](#quick-start)

```
use TypeLang\Mapper\Mapping\MapType;

class ExampleObject
{
    public function __construct(
        #[MapType('list')]
        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, but array(3)["first", "second", ""] given at $.names[2]
```

Benchmarks
----------

[](#benchmarks)

Results [here](https://github.com/php-type-language/mapper/actions/workflows/bench.yml)like [this](https://github.com/php-type-language/mapper/actions/runs/11924690471/job/33235475673#step:6:10).

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

```
object{
    name: string,
    items: list
}
```

The results are sorted by mode time.

### Denormalization

[](#denormalization)

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

benchmarkmemoryminmoderstdevTypeLangStrictAttributesBench1.929mb91.180μs105.264μs±6.99%TypeLangStrictPhpDocBench2.048mb98.860μs108.488μs±4.40%TypeLangPhpDocBench2.050mb103.380μs106.407μs±5.91%TypeLangAttributesBench1.930mb104.490μs113.736μs±4.23%JMSAttributesBench3.141mb137.040μs142.373μs±6.78%ValinorBench2.701mb227.370μs252.458μs±4.59%SymfonyPHPStanExtractorBench3.678mb371.650μs392.908μs±2.86%SymfonyPhpDocExtractorBench4.027mb379.740μs387.303μs±3.21%### Normalization

[](#normalization)

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

benchmarkmemoryminmoderstdevValinorBench1.966mb62.570μs69.184μs±3.99%TypeLangStrictAttributesBench1.845mb81.090μs88.343μs±6.75%TypeLangPhpDocBench1.965mb81.800μs90.504μs±5.99%TypeLangAttributesBench1.891mb85.320μs89.900μs±5.15%TypeLangStrictPhpDocBench1.967mb89.920μs94.865μs±2.62%SymfonyPHPStanExtractorBench2.086mb93.160μs100.173μs±5.41%SymfonyPhpDocExtractorBench2.405mb96.290μs98.729μs±4.17%JMSAttributesBench3.770mb131.420μs150.310μs±5.85%

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance71

Regular maintenance activity

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~17 days

Total

11

Last Release

160d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (214 commits)")[![root-aza](https://avatars.githubusercontent.com/u/13816704?v=4)](https://github.com/root-aza "root-aza (4 commits)")

---

Tags

data-mapperdenormalizerdeserializerhydratormappermarshalmarshallernormalizerserializertransformertypelangtypesunmarshalnormalizerserializermapperhydratortransformerMarshaltypesdenormalizerunmarshal

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/type-lang-mapper/health.svg)

```
[![Health](https://phpackages.com/badges/type-lang-mapper/health.svg)](https://phpackages.com/packages/type-lang-mapper)
```

###  Alternatives

[json-mapper/json-mapper

Map JSON structures to PHP classes

2181.1M22](/packages/json-mapper-json-mapper)[goetas-webservices/xsd2php

Convert XSD (XML Schema) definitions into PHP classes and JMS metadata

2411.6M37](/packages/goetas-webservices-xsd2php)[patchlevel/hydrator

Hydrator

16488.4k3](/packages/patchlevel-hydrator)[thunderer/serializard

Flexible serializer

2767.3k1](/packages/thunderer-serializard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
