PHPackages                             emreuyguc/structured-mapper-bundle - 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. emreuyguc/structured-mapper-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

emreuyguc/structured-mapper-bundle
==================================

A Symfony bundle for the emreuyguc/structured-mapper package that provides powerful object-to-object data transformation using structured mapping.

v0.1.3-rc1(1y ago)25MITPHPPHP &gt;=8.2

Since Apr 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/emreuyguc/symfony-structured-mapper-bundle)[ Packagist](https://packagist.org/packages/emreuyguc/structured-mapper-bundle)[ Docs](https://github.com/emreuyguc/symfony-structured-mapper-bundle)[ RSS](/packages/emreuyguc-structured-mapper-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (15)Versions (6)Used By (0)

Symfony Structured Mapper Bundle
================================

[](#symfony-structured-mapper-bundle)

[![PHP Version](https://camo.githubusercontent.com/4f0ff8d47b7c73441eb92a1f49af61c2d6521b14113c8fd85fac4416c863e7cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d626c7565)](https://camo.githubusercontent.com/4f0ff8d47b7c73441eb92a1f49af61c2d6521b14113c8fd85fac4416c863e7cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d626c7565)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)[![Author](https://camo.githubusercontent.com/85efbf2576652c697d47d0558e6ab14aa231e5f450142da0fa1bc9df956a1b02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d656d726575796775632d6f72616e6765)](https://camo.githubusercontent.com/85efbf2576652c697d47d0558e6ab14aa231e5f450142da0fa1bc9df956a1b02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d656d726575796775632d6f72616e6765)

This Symfony bundle enables seamless usage of the `emreuyguc/structured-mapper` package within Symfony applications.
It is designed to manage DTO ↔ Entity transformations in a simple and powerful way.

Features
--------

[](#features)

- **Mapping Definition via Attributes:** Ability to define transformation rules using attributes.
- **Bidirectional Mapping Definition:** Ability to define transformation rules in either the source or target class.
- **Property-Based Mapping:** Ability to define transformations directly on class properties.
- **Context Passing and Usage:** Ability to pass context data during mapping.
- **Value Transformers:** A structure for type and data transformations using value transformers.
- **Built-in Transformers:** Comes with built-in value transformers for common cases such as Doctrine Entity, Enum, Array item, etc.
- **Custom Mapper Definitions:** Ability to define custom transformation classes. (see: MapperRegistry and MapperInterface)
- **Array Item Transformation:** Ability to transform array items and process each element with a value transformer. (see: ValueTransformer/ArrayItemTransform/ArrayItemTransformer.php)
- **Sub Object Transformation Definition:** Ability to define transformations for child objects. (see: ValueTransformer/ObjectTransform/WithMapper.php)

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

[](#installation)

Add the Euu Structured Mapper to your project using Composer:

```
composer require emreuyguc/structured-mapper-bundle
```

Usage
-----

[](#usage)

### Accessing the Mapper Service

[](#accessing-the-mapper-service)

You can use Symfony autowiring as follows:

```
public function __construct(private readonly StructuredMapper $mapper)
{
}
```

Alternatively, you can call the `structured_mapper` service from the container.

### Usage

[](#usage-1)

```
use Euu\Bundle\StructuredMapperBundle\StructuredMapper\StructuredMapper;

$mapper = $container->get('structured_mapper');

$inputDto = new InputDto();

$mapper->map(sourceObject: $source, targetClass: MyEntity::class, context: [
    //object mapper context parameters..
]);
```

### Configuration

[](#configuration)

src/config/packages/structured\_mapper.yaml

```
structured_mapper:
    default_mapper_context:
        # see ObjectMapper settings
    cache:
        enabled: true
        ttl: 3600
        prefix: 'structured_mapper.'
        service: 'cache.app'
        preload:
            enabled: true
            readers:
                attribute_reader:
                    instance_of: ~ #example : 'App\Dto\BaseDto'
                    read_directory: ~ #currently not supported
```

### Populate

[](#populate)

```
$inputDto = new InputDto();
$target = new Person(name:'Emre', age: 28);

$mapper->map(sourceObject: $source, targetClass: Person::class, context: [
    ObjectMapper::TO_POPULATE => $target
]);

```

### Context Parameters

[](#context-parameters)

The default context parameters defined for the ObjectMapper are as follows;

```
    public const SKIP_NULL_VALUES = 'skip_null_values';
    public const TO_POPULATE = 'to_populate';
    public const ALLOW_AUTO_MAPPING = 'allow_auto_mapping';
    public const GROUPS = 'groups';

    public const AUTO_SUB_MAPPING = 'auto_sub_mapping';

    public const TYPE_ENFORCEMENT = 'type_enforcement';
    public const ARRAY_ADD_METHOD = 'array_add_method';
    public const ARRAY_CLEAR_METHOD = 'array_clear_method';
    public const ARRAY_CLEAR_EXPRESSION = 'array_clear_expression';

```

You can find the latest list of parameters [here](https://github.com/emreuyguc/php-structured-mapper/blob/main/src/Mapper/ObjectMapper/ObjectMapper.php).

- skip\_null\_values: skips mapping for null values
- to\_populate: maps into an existing object
- allow\_auto\_mapping: maps matching property names automatically even if mappings are not explicitly defined
- auto\_sub\_mapping: inactive
- groups: inactive
- type\_enforcement: enforces type validation between source and target
- array\_add\_method: reserved for value transformer
- array\_clear\_method: reserved for value transformer
- array\_clear\_expression: reserved for value transformer

### Class-Level Mapping

[](#class-level-mapping)

```
  #[MapTo(
      ProductEntity::class,
      mappings: [
          new Mapping('productCode', 'productNumber'),
          new Mapping('barcode', 'barcodeNumber')
      ],
      mapperContext: [
          ObjectMapper::SKIP_NULL_VALUES => true,
          ObjectMapper::ALLOW_AUTO_MAPPING => false,
          ObjectMapper::TYPE_ENFORCEMENT => false
      ])]
  class ProductDto{
```

### Property-Level Mapping

[](#property-level-mapping)

```
  class StockDto
  {
      #[OnMapTo(StockEntity::class, targetPath: 'stock')]
      public ?int $stockCount = null;

      #[OnMapTo(StockEntity::class, targetPath: 'warehouse')]
      public ?string $stockWarehouse = null;
  }
```

### Accessing Sub Objects

[](#accessing-sub-objects)

For a nested target property:

```
    #[OnMapTo(ProductEntity::class, targetPath: 'owner.fullName')]
    public string $ownerName;
```

For a nested source property:

```
  #[MapTo(
      ProductEntity::class,
      mappings: [
          new Mapping('stock.stockWarehouse', 'stockWarehouse')
      ])]
  class ProductDto
  {
```

#### Sub Object Transformation

[](#sub-object-transformation)

```
    #[OnMapTo(
        targetClass: ProductEntity::class,
        transformerMeta: new WithMapper(targetClass: StockEntity::class)
    )]
    public StockDto $stock;
```

#### Array Transformation

[](#array-transformation)

```
    #[OnMapTo(ProductEntity::class, transformerMeta: new ArrayItemTransform(
        itemTransformerMeta: new WithMapper(targetClass: SellerEntity::class)
    ))]
    public array $sellers;
```

### Using Value Transformers

[](#using-value-transformers)

#### ImplodeTransformer

[](#implodetransformer)

Note: `ImplodeTransformer` merges multiple source properties into one target property. Can only be used with `MapTo` as `OnMapTo` only supports single source.

```
  #[MapTo(
      ProductEntity::class,
      mappings: [
          new Mapping(['sku', 'code'], 'productCode', new ImplodeTransform('-')),
     ])]
```

#### ExplodeTransformer

[](#explodetransformer)

```
    #[OnMapTo(ProductEntity::class, targetPath: 'model', transformerMeta: new ExplodeTransform('-', 1, 2))]
    #[OnMapTo(ProductEntity::class, targetPath: 'brand', transformerMeta: new ExplodeTransform('-', 0, 2))]
    public string $brandModel;
```

#### EnumTransformer

[](#enumtransformer)

```
    #[OnMapTo(ProductEntity::class, targetPath: 'unit', transformerMeta: new EnumTransform(UnitType::class))]
    public string $unit;
```

#### EntityResolve Transformer

[](#entityresolve-transformer)

Basic usage with default ID resolver:

```
    #[OnMapTo(ProductEntity::class, targetPath: 'taxGroup', transformerMeta: new EntityResolve(TaxGroup::class))]
    public string $sellTaxGroupId;
```

Advanced usage for updatable collections:

```
    #[OnMapTo(
        ProductEntity::class,
        targetPath: 'subCategories',
        transformerMeta: new ArrayItemTransform(
            itemTransformerMeta: new EntityResolve(SubCategoryEntity::class),
            transformerContext: [
                ArrayItemTransformer::USE_ADD_METHOD => 'addSubCategory',
                ArrayItemTransformer::CLEAR_METHOD => 'subCategories.clear()',
                ArrayItemTransformer::CLEAR_EXPRESSION => "'update' in context['groups']"
            ]
        )
    )]
    public array $subCategoryIds;
```

EntityResolve class parameter descriptions:

- ?string $repositoryMethod = 'find': set custom repository method
- ?array $findArguments = null: extra arguments to be passed to the method
- bool $nullable = false: suppresses error if entity is not found

Limitations and Considerations
------------------------------

[](#limitations-and-considerations)

- **Object Constructor Issue:** Objects with constructors cannot be instantiated during mapping. (Priority: High)
- **Reverse Mapping Support:** If `a -> b` mappings are defined, reverse mappings (`b -> a`) are theoretically possible, but currently unsupported. (Priority: Medium)
- **Type Conversion Mechanism:** No general type conversion mechanism is available. Users must handle it manually or set `type_enforcement` to false for simple cases. (Priority: Low)
- **Property Naming:** Properties must be mapped manually. An automatic naming converter could be added. (Priority: Medium)
- **Cache Mechanism:** No caching mechanism exists yet. A suitable structure can be added. (Priority: High)
- **Map Control:** A `canMap` method could be added for verification. (Priority: High)
- **Auto Sub-Object Mapping:** Auto-mapping of child objects based on type hints can be added. (Priority: Medium)
- **Transformation Type Check for Custom Mappers:** Source and target types are not currently checked in custom mappers. (Priority: High)
- **Expression Language Support for Entity Resolving:** Expression-based custom parameters can be introduced. (Priority: Low)
- **Tests:** Tests will be implemented. (Priority: High)
- **Ignore/Allow/Group Structure:** Group-based inclusion/exclusion rules can be added. (Priority: Low)
- **Inheritance Support:** Mapping rules could be inherited by subclasses. (Priority: Low)
- **Sub Object Loop Limitation:** Prevent infinite loops or add error handling during recursive sub-object mapping. (Priority: Medium)

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE.md).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance47

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

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.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

394d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/998bfee719bb7fec056c6aecfded8ac88195951e15127a16b17c0512765592a3?d=identicon)[emreuyguc](/maintainers/emreuyguc)

---

Top Contributors

[![emreuyguc](https://avatars.githubusercontent.com/u/4369721?v=4)](https://github.com/emreuyguc "emreuyguc (12 commits)")

---

Tags

attributesdoctrinedtoentitymapperobject-mappingobject-transformphp-libraryphp8symfonysymfony-bundlesymfony-dtosymfony-mappingvalue-transformerphpsymfonybundlemappingmappertransformationdata mapperdtoobject mapperobject-to-objectdata-transformerphp-mapperentity-mapperdto-mapperemreuygucstructured-mapper

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/emreuyguc-structured-mapper-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/emreuyguc-structured-mapper-bundle/health.svg)](https://phpackages.com/packages/emreuyguc-structured-mapper-bundle)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[kreait/firebase-bundle

Symfony Bundle for the Firebase Admin SDK

1534.7M2](/packages/kreait-firebase-bundle)[event4u/data-helpers

Framework-agnostic PHP library for data mapping, DTOs and utilities. Includes DataMapper, SimpleDto/LiteDto, DataAccessor/Mutator/Filter and helper classes (MathHelper, EnvHelper, etc.). Works with Laravel, Symfony/Doctrine or standalone PHP.

1421.5k](/packages/event4u-data-helpers)[onurb/doctrine-yuml-bundle

Symfony Bundle to visualize the mapping of your entities with Yuml

4198.6k](/packages/onurb-doctrine-yuml-bundle)[rekalogika/mapper

An object mapper for PHP and Symfony. Maps an object to another object. Primarily used for transforming an entity to a DTO and vice versa.

3847.7k1](/packages/rekalogika-mapper)

PHPackages © 2026

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