New version of DTO conversion to php
Today is the release of version 2.0 of the ClassTransformer package.
This library will allow you to easily convert any data set into the object you need. You are not required to change the structure of classes, inherit them from external modules, etc. No dancing with tambourines — just data and the right class.
Base usage:
What has changed in 2.0
1 Alias
Added alias support for properties. This can be useful when data is taken from various sources.
2 Mutator for setter
If a field requires additional processing during its initialization, you can make mutator. set{Attribute}Attribute method on your class where {Attribute} is cased name of the property you wish to access.
3 afterTransform
Sometimes it is necessary to perform a post-check for data consistency or simply output a log. The afterTransform method will be called when the object is transformed
4 Support enum from php 8.1+
5 transformCollection
Added transformCollection method to properly transform your collections
5 Refactoring code
Refactoring allowed us to get a lot of acceleration
Comparison
An analysis of current similar solutions was also carried out. Unfortunately, some packages force the developer to inherit classes from their interfaces, which I really don’t want. Some dictate their class structure, which also entails changes in their established structure.
There are also many implemented for a specific framework, and there is no way to reuse them normally in another stack.
Below is a comparison of the speed of the closest competitors to my package
The sources of my comparison are published on github