PHPackages                             inlm/mappers - 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. inlm/mappers

ActiveLibrary

inlm/mappers
============

Mappers for Lean Mapper.

v3.1.0(10mo ago)213.1k↓37.1%1BSD-3-ClausePHPPHP 8.0 - 8.4CI passing

Since Aug 22Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/inlm/mappers)[ Packagist](https://packagist.org/packages/inlm/mappers)[ Fund](https://www.janpecha.cz/donate/)[ RSS](/packages/inlm-mappers/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (9)Used By (1)

Inlm\\Mappers
=============

[](#inlmmappers)

[![Build Status](https://github.com/inlm/mappers/workflows/Build/badge.svg)](https://github.com/inlm/mappers/actions)[![Downloads this Month](https://camo.githubusercontent.com/2b2f33752f528c6719488f2c6e6d3f790ee86cbc20b2967184052db5b97d623d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696e6c6d2f6d6170706572732e737667)](https://packagist.org/packages/inlm/mappers)[![Latest Stable Version](https://camo.githubusercontent.com/163e879ef7729074546e9d960036fe7f066b93a675550987346063a1fdddc136/68747470733a2f2f706f7365722e707567782e6f72672f696e6c6d2f6d6170706572732f762f737461626c65)](https://github.com/inlm/mappers/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/inlm/mappers/blob/master/license.md)

Mappers for Lean Mapper.

[![Donate](https://camo.githubusercontent.com/101b981194f1dafbf9c42e19c3034fe2d724e75be972cef0f4477074997834db/68747470733a2f2f6275796d65636f666665652e696e746d2e6f72672f696d672f646f6e6174652d62616e6e65722e76312e737667)](https://www.janpecha.cz/donate/)

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

[](#installation)

[Download a latest package](https://github.com/inlm/mappers/releases) or use [Composer](http://getcomposer.org/):

```
composer require inlm/mappers

```

`Inlm\Mappers` requires PHP 8.0 or later.

Usage
-----

[](#usage)

MapperEntityTableColumnNote`Inlm\Mappers\DefaultMapper``OrderItem``orderitem``customerName`*only extends `LeanMapper\DefaultMapper`*`Inlm\Mappers\CamelCaseMapper``OrderItem``orderItem``customerName`There is [issue](https://dev.mysql.com/doc/refman/5.5/en/identifier-case-sensitivity.html) for MySQL on OS Windows.`Inlm\Mappers\UnderScoreMapper``OrderItem``order_item``customer_name``Inlm\Mappers\DynamicMapper`~~~See below.`Inlm\Mappers\PrefixMapper`~~~See below.`Inlm\Mappers\RowMapper`~~~See below.`Inlm\Mappers\StiMapper`~~~See below.### DynamicMapper

[](#dynamicmapper)

Dynamic mapper uses explicit mapping of entities and tables.

```
$mapper = new DynamicMapper;
$mapper->setMapping(
	'order_items', // table name - required
	'OrderItem', // entity class - optional
	'OrderItemRepository', // repository class - optional
	'item_id' // primary key - optional
);
```

If there's no mapping for entity or table, call is passed to fallback mapper (`LeanMapper\DefaultMapper` by default):

```
$mapper = new DynamicMapper;
$mapper->getTable('OrderItem'); // returns 'orderitem'

$mapper = new DynamicMapper(new Inlm\Mappers\UnderScoreMapper);
$mapper->getTable('OrderItem'); // returns 'order_item'
```

### PrefixMapper

[](#prefixmapper)

PrefixMapper adds &amp; removes prefix from table names.

```
$mapper = new PrefixMapper('prefix_');
$mapper = new PrefixMapper('prefix_', $fallbackMapper);
```

PrefixMapper only processes prefixes in table names, everything else is given to fallback mapper (`LeanMapper\DefaultMapper` by default):

```
$mapper = new PrefixMapper('prefix_');
echo $mapper->getTable('OrderItem'); // prints 'prefix_orderitem'

$mapper = new PrefixMapper('prefix_', new Inlm\Mappers\UnderScoreMapper);
echo $mapper->getTable('OrderItem'); // prints 'prefix_order_item'
```

### RowMapper

[](#rowmapper)

RowMapper maps values to / from `LeanMapper\Row` (requires Lean Mapper 3.5+).

```
$mapper = new RowMapper;
$mapper = new RowMapper($fallbackMapper);
$mapper->registerFieldMapping($entity, $field, $fromDbValue, $toDbValue);
$mapper->registerFieldMapping(
	Model\Entity\Client::class,
	'website',
	function ($dbValue) {
		return new Website($dbValue);
	},
	function (Website $rowValue) {
		return $rowValue->getUrl();
	}
);

// multi column mapping
$mapper->registerMultiValueMapping(
	Model\OrderItem::class,
	'price',
	function (array $values, $rowField) {
		return new Price($values[$rowField . '_total'], $values[$rowField . '_currency']);
	},
	function (Price $price, $rowField) {
		return [
			$rowField . '_total' => $price->getPrice(),
			$rowField . '_currency' => $price->getCurrency(),
		];
	}
);
```

### StiMapper

[](#stimapper)

StiMapper simplifies working with Single Table Inheritance.

```
$mapper = new StiMapper;
$mapper = new StiMapper($fallbackMapper);
```

Registration of STI types:

```
$mapper->registerStiType($baseEntity, $typeValue, $entityClass);
$mapper->registerStiType(Entities\Client::class, 'company', Entities\ClientCompany::class);
$mapper->registerStiType(Entities\Client::class, 'individual', Entities\ClientIndividual::class);
```

Default STI type column is named `type`, you can change it with:

```
$mapper->registerTypeField(Entities\Client::class, 'clientType');
```

You can limit `LeanMapper\Fluent` for specific STI type:

```
$fluent = $connection->select('*')->from('client');
$mapper->applyStiMapping($fluent, Entities\ClientCompany::class);
echo $fluent; // SELECT * FROM `client` WHERE `client`.`clientType` = 'company'
```

### How change default entity namespace

[](#how-change-default-entity-namespace)

```
$mapper = new Inlm\Mappers\DefaultMapper('App\Entity');
$mapper = new Inlm\Mappers\CamelCaseMapper('App\Entity');
$mapper = new Inlm\Mappers\UnderScoreMapper('App\Entity');
```

### Recommended order of mappers

[](#recommended-order-of-mappers)

- `RowMapper`
- `StiMapper`
- `PrefixMapper`
- `DynamicMapper`
- `DefaultMapper` / `CamelCaseMapper` / `UnderScoreMapper`

---

License: [New BSD License](license.md)
Author: Jan Pecha,

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance53

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% 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 ~409 days

Recently: every ~444 days

Total

8

Last Release

325d ago

Major Versions

v1.1.0 → v2.0.02020-08-14

v2.1.1 → v3.0.02021-02-21

PHP version history (4 changes)v1.0.0PHP &gt;=5.4.0

v2.0.0PHP &gt;=5.6.0

v3.0.0PHP &gt;=7.2.0

v3.1.0PHP 8.0 - 8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c980b1511b4a0350442dc23d89c99d4d9a2411b7e765d52c133ccacf616968b?d=identicon)[janpecha](/maintainers/janpecha)

---

Top Contributors

[![janpecha](https://avatars.githubusercontent.com/u/637719?v=4)](https://github.com/janpecha "janpecha (45 commits)")

---

Tags

leanmapperphp

### Embed Badge

![Health badge](/badges/inlm-mappers/health.svg)

```
[![Health](https://phpackages.com/badges/inlm-mappers/health.svg)](https://phpackages.com/packages/inlm-mappers)
```

###  Alternatives

[mbohuslavek/leanmapper-query

Concept of Query Object for LeanMapper

1011.9k2](/packages/mbohuslavek-leanmapper-query)

PHPackages © 2026

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