PHPackages                             danilovl/object-dto-mapper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. danilovl/object-dto-mapper

ActivePackage[Utility &amp; Helpers](/categories/utility)

danilovl/object-dto-mapper
==========================

Mapper that converts an object to a DTO.

v1.0.0(4mo ago)025MITPHPPHP ^8.5

Since Sep 14Pushed 4mo agoCompare

[ Source](https://github.com/danilovl/object-dto-mapper)[ Packagist](https://packagist.org/packages/danilovl/object-dto-mapper)[ RSS](/packages/danilovl-object-dto-mapper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

[![phpunit](https://github.com/danilovl/object-dto-mapper/actions/workflows/phpunit.yml/badge.svg)](https://github.com/danilovl/object-dto-mapper/actions/workflows/phpunit.yml)[![downloads](https://camo.githubusercontent.com/e392f07582bbfac4155c89c4485537c82f2dd83a4c9c0bb3855101e690aacad0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64616e696c6f766c2f6f626a6563742d64746f2d6d6170706572)](https://packagist.org/packages/danilovl/object-dto-mapper)[![latest Stable Version](https://camo.githubusercontent.com/b83bd511114a1f1f6d780529ae0980c39390cfdd70d911c2211dbe764ee6e5c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e696c6f766c2f6f626a6563742d64746f2d6d6170706572)](https://packagist.org/packages/danilovl/object-dto-mapper)[![license](https://camo.githubusercontent.com/d791fd6c2de5395b5f35dae226af9cfff36ab53ec20e0b892dffc298d9646252/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64616e696c6f766c2f6f626a6563742d64746f2d6d6170706572)](https://packagist.org/packages/danilovl/object-dto-mapper)

Object to DTO mapper
====================

[](#object-to-dto-mapper)

Description
-----------

[](#description)

A lightweight mapper that converts an object (Entity/model) to a DTO based on the DTO constructor signature.

Mapping is controlled via the #\[Map\] attribute on DTO properties (constructor-promoted properties are supported).

It supports conditional mapping (if), value transformations (transform), collections and nested objects, as well as filtering by Symfony Serializer Groups.

### Key features

[](#key-features)

- Map by matching a property name or from another path via Map(source)
- Conditional mapping: bool, callable, or container service (Map(if) / Map(ifContainer))
- Transformations: callable/class or container service (Map(transform)/Map(transformContainer))
- Auto-format DateTimeInterface -&gt; ATOM if no transform is specified
- Map collections into target DTO via Map(target)
- Nested objects are mapped recursively based on the constructor parameter type
- Filter DTO properties by groups (allowGroups/ignoreGroups) using Symfony\\Component\\Serializer\\Attribute\\Groups on DTO

Requirements
------------

[](#requirements)

- PHP 8.5+
- symfony/property-access 8.0+
- symfony/serializer 8.0+

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

[](#installation)

Install the package via Composer:

```
 composer require danilovl/object-dto-mapper
```

Quick start
-----------

[](#quick-start)

Example: we have an entity and a DTO.

```
