PHPackages                             janpecha/leanmapper-extension - 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. [Framework](/categories/framework)
4. /
5. janpecha/leanmapper-extension

ActiveLibrary[Framework](/categories/framework)

janpecha/leanmapper-extension
=============================

LeanMapper extension for Nette DI

v1.0.0(2y ago)410.7k[1 issues](https://github.com/janpecha/leanmapper-extension/issues)1BSD-3-ClausePHPPHP &gt;=7.2.0

Since Sep 14Pushed 1y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (12)Used By (1)

LeanMapper-extension
====================

[](#leanmapper-extension)

[![Build Status](https://github.com/janpecha/leanmapper-extension/workflows/Build/badge.svg)](https://github.com/janpecha/leanmapper-extension/actions)[![Downloads this Month](https://camo.githubusercontent.com/13062c30dacf7a97f832805c5c3d8fb3f95df8712aa8da28a27469a1b3eb81fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a616e70656368612f6c65616e6d61707065722d657874656e73696f6e2e737667)](https://packagist.org/packages/janpecha/leanmapper-extension)[![Latest Stable Version](https://camo.githubusercontent.com/2952f50320efa66387c91862a20edbd77bc7b5505fc573449799feeb733991da/68747470733a2f2f706f7365722e707567782e6f72672f6a616e70656368612f6c65616e6d61707065722d657874656e73696f6e2f762f737461626c65)](https://github.com/janpecha/leanmapper-extension/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/janpecha/leanmapper-extension/blob/master/license.md)

[Lean Mapper](http://leanmapper.com/) extension for [Nette](https://nette.org).

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

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

[](#installation)

[Download a latest package](https://github.com/janpecha/leanmapper-extension/releases) or use [Composer](http://getcomposer.org/):

```
composer require janpecha/leanmapper-extension

```

Extension requires:

- PHP 7.2 or later
- Nette 3.0 or later
- LeanMapper 4.0 or later

Usage
-----

[](#usage)

```
extensions:
	leanmapper: JP\LeanMapperExtension\LeanMapperExtension

leanmapper:
	# database connection
	username: ...
	password: ...
	database: ...
```

Configuration
-------------

[](#configuration)

### Database connection

[](#database-connection)

```
leanmapper:
	# required
	username: ...
	password: ...
	database: ...

	# optional
	connection: LeanMapper\Connection
	host: localhost
	driver: mysqli
	lazy: true
	profiler: ...    # on|off or NULL => enabled in debug mode, disabled in production mode
	charset: utf8mb
```

### Entities

[](#entities)

```
leanmapper:
	entityFactory: LeanMapper\DefaultEntityFactory
	entityMapping:
		table: EntityClass

		table:
			entity: EntityClass
			repository: RepositoryClass # only mapping, you need manually register repository to DI
			primaryKey: table_primary_key

		articles:
			entity: App\Model\Article
			primaryKey: article_id
```

### Mapper

[](#mapper)

```
leanmapper:
	mapper: true # bool
	defaultEntityNamespace: 'Model\Entity'
	nameMapping: camelcase # default | camelcase | underscore
	prefix: null
```

Support for addons
------------------

[](#support-for-addons)

```
use Nette\DI\CompilerExtension;
use JP\LeanMapperExtension\IEntityProvider;

class FooExtension extends CompilerExtension implements IEntityProvider
{
	// from IEntityProvider
	function getEntityMappings()
	{
		return array(
			array(
				'table' => 'foo_articles',
				'primaryKey' => 'id',
				'entity' => Foo\Model\Article::class,
				'repository' => Foo\Model\ArticleRepository::class, # only mapping, you need manually register repository to DI
			),
			// ...
		);
	}
}
```

STI mapping

```
use Nette\DI\CompilerExtension;
use JP\LeanMapperExtension\IStiMappingProvider;

class FooExtension extends CompilerExtension implements IStiMappingProvider
{
	function getStiMappings()
	{
		return [
			Model\Entity\Client::class => [ // base entity
				// type => target entity
				'company' => Model\Entity\ClientCompany::class,
			],
			// ...
		];
	}

	function getStiTypeFields()
	{
		return [
			Model\Entity\Client::class => 'clientType',
		];
	}
}
```

Row mapping

```
use Nette\DI\CompilerExtension;
use JP\LeanMapperExtension\IRowMappingProvider;

class FooExtension extends CompilerExtension implements IRowMappingProvider
{
	function getRowFieldMappings()
	{
		return [
			\Model\Entity\OrderItem::class => [
				'currency' => [
					'fromDbValue' => [static::class, 'currencyFromDb'],
					'toDbValue' => [static::class, 'currencyToDb'],
				]
			],
			// ...
		];
	}

	function getRowMultiValueMappings()
	{
		return [
			\Model\Entity\OrderItem::class => [
				'price' => [
					'fromDbValue' => [static::class, 'priceFromDb'],
					'toDbValue' => [static::class, 'priceToDb'],
				],
			],
		];
	}

	static function currencyFromDb($value)
	{
		return strtoupper($value);
	}

	static function currencyToDb($value)
	{
		return strtolower($value);
	}

	static function priceFromDb(array $values)
	{
		return [$values['price'], $values['currency']];
	}

	static function priceToDb($value)
	{
		return [
			'price' => $value[0],
		];
	}
}
```

---

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

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance22

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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 ~322 days

Recently: every ~218 days

Total

11

Last Release

1042d ago

Major Versions

v0.13.3 → v1.0.02023-07-12

PHP version history (3 changes)v0.9.0PHP &gt;=5.3.0

v0.11.0PHP &gt;=5.6.0

v1.0.0PHP &gt;=7.2.0

### 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 (64 commits)")

---

Tags

leanmapperleanmapper-extensionnettephp

### Embed Badge

![Health badge](/badges/janpecha-leanmapper-extension/health.svg)

```
[![Health](https://phpackages.com/badges/janpecha-leanmapper-extension/health.svg)](https://phpackages.com/packages/janpecha-leanmapper-extension)
```

###  Alternatives

[nette/bootstrap

🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.

68535.8M592](/packages/nette-bootstrap)[nette/nette

👪 Nette Framework - innovative framework for fast and easy development of secured web applications in PHP (metapackage)

1.6k2.8M335](/packages/nette-nette)[contributte/webpack

Webpack integration for Nette Framework.

471.0M1](/packages/contributte-webpack)[nette/web-project

Nette: Standard Web Project

10991.8k](/packages/nette-web-project)[kdyby/autowired

Syntax sugar for working with services in Nette Framework

30885.7k9](/packages/kdyby-autowired)[brandembassy/slim-nette-extension

19190.2k](/packages/brandembassy-slim-nette-extension)

PHPackages © 2026

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