PHPackages                             bluepsyduck/mapper-manager - 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. bluepsyduck/mapper-manager

ActiveLibrary

bluepsyduck/mapper-manager
==========================

A manager for mapping objects to other ones.

1.3.0(4y ago)15.2k2GPL-3.0-or-laterPHPPHP ^8.0

Since Feb 8Pushed 4y ago1 watchersCompare

[ Source](https://github.com/BluePsyduck/mapper-manager)[ Packagist](https://packagist.org/packages/bluepsyduck/mapper-manager)[ Docs](https://github.com/BluePsyduck/mapper-manager)[ RSS](/packages/bluepsyduck-mapper-manager/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (6)Used By (2)

Mapper Manager
==============

[](#mapper-manager)

[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/54c4849b163a42728bde210553d1cce54882413de4414276fb33bbefb662e406/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f426c75655073796475636b2f6d61707065722d6d616e61676572)](https://github.com/BluePsyduck/mapper-manager/releases)[![GitHub](https://camo.githubusercontent.com/c42af1e0ffe4a3931ac3bf8f84dc0cde557cdc8931182f065d8869e606fc7c44/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f426c75655073796475636b2f6d61707065722d6d616e61676572)](LICENSE.md)[![build](https://camo.githubusercontent.com/d6159347f7bb294bb305821d09de518f9ac2701ec48825f1cf112ca9eb1cd40b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f426c75655073796475636b2f6d61707065722d6d616e616765722f43493f6c6f676f3d676974687562)](https://github.com/BluePsyduck/mapper-manager/actions)[![Codecov](https://camo.githubusercontent.com/b96894d43417418be696fb2f4369880873481434f033065824321874f21d505d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f426c75655073796475636b2f6d61707065722d6d616e616765723f6c6f676f3d636f6465636f76)](https://codecov.io/gh/BluePsyduck/mapper-manager)

The Mapper Manager is, as the name already suggests, a manager of mappers between different types of objects.

Mapper
------

[](#mapper)

The mapper supports different types of mappers, which have the difference in how they evaluate whether they can map a certain pair of objects or not. Each type of mapper comes with an interface and a corresponding adapter for the manager to handle this type of mappers. New types can always be added in the client code if there is a need for them.

If a mapper requires access to the `MapperManager` to e.g. map other objects, you have to implement the `MapperManagerAwareInterface` to have it get injected into your mapper instance to avoid having circular dependencies. You may use the `MapperManagerAwareTrait` to implement this interface with a simple setter method.

### Static Mapper

[](#static-mapper)

A static mapper implementing the `StaticMapperInterface` knows the combination of source and destination object it supports based only on the classes, without knowing the actual instances of the objects. The support is evaluated once when the mapper is added to the manager.

Note: The classes of source and destination must match exactly, the static mapper does not check for any inheritance. For example, if there is a class `A` and a class `B extends A`, and the mapper returns `A` as supported class, it won't match if an instance of `B` is passed instead. If inheritance must be supported, use a dynamic mapper instead.

It is recommended to always use static mappers if possible, as matching the mapper in the manager is faster with static mappers than with dynamic ones.

#### Example

[](#example)

```
