https://github.com/wundii/data-mapper-symfony-bundle
A Symfony bundle providing seamless integration for the wundii/data-mapper
https://github.com/wundii/data-mapper-symfony-bundle
deserialisation hydrations json mapper neon object php symfony symfony-bundle xml yaml
Last synced: about 2 months ago
JSON representation
A Symfony bundle providing seamless integration for the wundii/data-mapper
- Host: GitHub
- URL: https://github.com/wundii/data-mapper-symfony-bundle
- Owner: wundii
- License: mit
- Created: 2025-06-08T08:46:45.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-06-18T08:19:48.000Z (11 months ago)
- Last Synced: 2025-06-18T08:35:33.142Z (11 months ago)
- Topics: deserialisation, hydrations, json, mapper, neon, object, php, symfony, symfony-bundle, xml, yaml
- Language: PHP
- Homepage:
- Size: 38.1 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/wundii/data-mapper-symfony-bundle/actions/workflows/code_quality.yml)
[](https://phpstan.org/)

[](https://www.php.net/)
[](https://getrector.com)
[](https://tomasvotruba.com/blog/zen-config-in-ecs)
[](https://phpunit.org)
[](https://codecov.io/github/wundii/data-mapper-symfony-bundle)
[](https://packagist.org/packages/wundii/data-mapper-symfony-bundle)
A Symfony integration for [wundii/data-mapper](https://github.com/wundii/data-mapper).
This library is an extremely fast and strictly typed object mapper built for modern PHP (8.2+).
It seamlessly transforms data from formats like CSV, JSON, NEON, XML, YAML, array, and standard objects into well-structured PHP objects.
Ideal for developers who need reliable and efficient data mapping without sacrificing code quality or modern best practices.
## Features
- Mapping source data into objects
- Mapping source data with a list of elements into a list of objects
- Initialize object via constructor, properties or methods
- Map nested objects, arrays of objects
- Class mapping for interfaces or other classes
- Custom root element for starting with the source data
- Auto-casting for `float` types (eu to us decimal separator)
- Target alias via Attribute for properties and methods
- Automatic data sorting for constructor parameters
## Supported Types
- `null`
- `bool`|`?bool`
- `int`|`?int`
- `float`|`?float`
- `string`|`?string`
- `array`
- `int[]`
- `float[]`
- `string[]`
- `object[]`
- `object`|`?object`
- `enum`|`?enum`
## Supported Formats
optional formats are marked with an asterisk `*`
- `array`
- `csv`
- `json`
- `neon`*
- `object`
- `public property`
- `public getters`
- `method toArray()`
- `attribute SourceData('...')`
- `xml`
- `yaml`*
## Installation
Require the bundle and its dependencies with composer:
```bash
composer require wundii/data-mapper-symfony-bundle
```
Include the bundle in your `bundles.php`:
```php
return [
// ...
Wundii\DataMapper\SymfonyBundle\DataMapperBundle::class => ['all' => true],
];
```
Create a Symfony configuration file `config/packages/data_mapper.yaml` with the command:
```bash
bin/console data-mapper:default-config
```
## Configuration File
The following setting options are available
```yaml
data_mapper:
data_config:
approach: 'CONSTRUCTOR|PROPERTY|SETTER' # ApproachEnum::SETTER
accessible: 'PRIVATE|PUBLIC' # AccessibleEnum::PUBLIC
class_map:
InterfaceOrClassName: 'ClassName', # Class mapping for interfaces or other classes
...: ...
```
## Use as Symfony DataMapper version
```php
dataMapper->request($request, TestClass::class);
// or you can use tryRequest to avoid exceptions, null will be returned instead
$testClass = $this->dataMapper->tryRequest($request, TestClass::class);
$this->dataMapper->getMapStatusEnum();
$this->dataMapper->getErrorMessage();
// Do something with $testClass
return $this->json(...);
}
}
```
## Use as native DataMapper version
```php
dataMapper->json($request->getContent(), TestClass::class);
// Do something with $testClass
return $this->json(...);
}
}
```