PHPackages                             walnut/lib\_modelmapper\_orm - 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. [Database &amp; ORM](/categories/database)
4. /
5. walnut/lib\_modelmapper\_orm

ActiveLibrary[Database &amp; ORM](/categories/database)

walnut/lib\_modelmapper\_orm
============================

052PHP

Since May 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kapitancho/walnut-lib-modelmapper-orm)[ Packagist](https://packagist.org/packages/walnut/lib_modelmapper_orm)[ RSS](/packages/walnut-lib-modelmapper-orm/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

ORM based Model Mapper
======================

[](#orm-based-model-mapper)

An adapter to use Relational Storage as a Model Mapper

Example
=======

[](#example)

This is a very simple data model - client.

```
class Client {
	public function __construct(
		public /*readonly*/ string $id,
		public /*readonly*/ string $name
	) {}
}
```

A serialization/deserialization logic is required.

```
/**
 * @implements ModelBuilder
 * @implements ModelParser
 */
final class ClientSerializer implements ModelBuilder, ModelParser {

	/**
	 * @param array $source
	 * @return Client
	 */
	public function build(array $source): object {
		return new Client(
			$source['id'] ?? '',
			$source['name'] ?? ''
		);
	}

	/**
	 * @param Client $source
	 * @return array
	 */
	public function parse(object $source): array {
		return [
			'id' => $source->id,
			'name' => $source->name
		];
	}
}
```

All serializers can be aggregated into a factory class

```
final class MapperFactory implements ModelBuilderFactory, ModelParserFactory {

	/**
	 * @param string $className
	 * @return ModelBuilder&ModelParser
	 */
	private function getSerializer(string $className): object /*ModelBuilder&ModelParser*/ {
		return match($className) {
			Client::class => new ClientSerializer,
			default => throw new RuntimeException("Unknown class $className")
		};
	}

	public function getBuilder(string $className): ModelBuilder {
		return $this->getSerializer($className);
	}

	public function getParser(string $className): ModelParser {
		return $this->getSerializer($className);
	}

}
```

### Defining the relational model

[](#defining-the-relational-model)

```
#[ModelRoot('clients')]
class ClientDbModel {
    public function __construct(
        #[Table("clients")]
        #[KeyField('id'), Fields('name')]
        public array $clients
    ) {}
}
```

Using a MySql storage

```
$sqlQuoter = new MysqlQuoter;
$queryExecutor = new PdoQueryExecutor($connector);
$dataModelFactory = new DataModelFactory($sqlQuoter, $queryExecutor);

$serializerFactory = new MapperFactory;

//Mapping between the models and their storage keys:
$configuration = new OrmModelMapperConfiguration(
    [Client::class => ClientDbModel::class]
);

//Mapper factory covering all models
$modelMapperFactory = new OrmModelMapperFactory(
    $configuration,
    new DataModelBuilder,
    $dataModelFactory,
    $serializerFactory,
    $serializerFactory,
    $sqlQuoter
);

//Take the mapper for the Client model
$mapper = $modelMapperFactory->getMapper(Client::class);

//Prepare two records
$firstClient = new Client('cl-1', 'Client 1');
$secondClient = new Client('cl-2', 'Client 2');

//Using the storage
$mapper->all(); //0 entries

$mapper->store($firstClient->id, $firstClient);
$mapper->store($secondClient->id, $secondClient);

$mapper->all(); //2 entries

$updatedSecondClient = new Client('cl-2', 'Client 2 new name');

$mapper->store($updatedSecondClient->id, $updatedSecondClient);
$mapper->all(); //2 entries

$mapper->byId($firstClient->id)->name; //Client 1
$mapper->byId($updatedSecondClient->id)->name; //Client 2 new name

$mapper->remove($firstClient->id);
$mapper->byId($firstClient->id); //null

$mapper->all(); //1 entry
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/792682?v=4)[Marian Kostadinov](/maintainers/kapitancho)[@kapitancho](https://github.com/kapitancho)

---

Top Contributors

[![kapitancho](https://avatars.githubusercontent.com/u/792682?v=4)](https://github.com/kapitancho "kapitancho (7 commits)")

### Embed Badge

![Health badge](/badges/walnut-lib-modelmapper-orm/health.svg)

```
[![Health](https://phpackages.com/badges/walnut-lib-modelmapper-orm/health.svg)](https://phpackages.com/packages/walnut-lib-modelmapper-orm)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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