Download the PHP package emreuyguc/structured-mapper-bundle without Composer
On this page you can find all versions of the php package emreuyguc/structured-mapper-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emreuyguc/structured-mapper-bundle
More information about emreuyguc/structured-mapper-bundle
Files in emreuyguc/structured-mapper-bundle
Package structured-mapper-bundle
Short Description A Symfony bundle for the emreuyguc/structured-mapper package that provides powerful object-to-object data transformation using structured mapping.
License MIT
Homepage https://github.com/emreuyguc/symfony-structured-mapper-bundle
Informations about the package structured-mapper-bundle
Symfony Structured Mapper Bundle
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
- 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
Add the Euu Structured Mapper to your project using Composer:
Usage
Accessing the Mapper Service
You can use Symfony autowiring as follows:
Alternatively, you can call the structured_mapper
service from the container.
Usage
Configuration
src/config/packages/structured_mapper.yaml
Populate
Context Parameters
The default context parameters defined for the ObjectMapper are as follows;
You can find the latest list of parameters here.
- 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
Property-Level Mapping
Accessing Sub Objects
For a nested target property:
For a nested source property:
Sub Object Transformation
Array Transformation
Using Value Transformers
ImplodeTransformer
Note: ImplodeTransformer
merges multiple source properties into one target property. Can only be used with MapTo
as OnMapTo
only supports single source.
ExplodeTransformer
EnumTransformer
EntityResolve Transformer
Basic usage with default ID resolver:
Advanced usage for updatable collections:
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
- 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
This package is licensed under the MIT License.
All versions of structured-mapper-bundle with dependencies
doctrine/orm Version ^3.3
emreuyguc/structured-mapper Version ^0.1
psr/cache Version ^3.0
symfony/config Version ^7.2
symfony/dependency-injection Version ^7.2
symfony/http-kernel Version ^7.2