Are there any .Net automapper equivalent libraries but for php?
i.e. something that will copy all info from one class to another, for example user
<-> userDTO
.
If you have to do complex mapping behavior, it might be better to avoid using AutoMapper for that scenario. Reverse mapping can get very complicated very quickly, and unless it's very simple, you can have business logic showing up in mapping configuration.
Automapper is slower when mapping a single object and collections but there is one exception. Automapper is considerably faster when mapping a List<T> of objects on . NET Core (It's still slower on full .
AutoMapper is used whenever there are many data properties for objects, and we need to map them between the object of source class to the object of destination class, Along with the knowledge of data structure and algorithms, a developer is required to have excellent development skills as well.
How AutoMapper works? AutoMapper internally uses a great concept of programming called Reflection. Reflection in C# is used to retrieve metadata on types at runtime. With the help of Reflection, we can dynamically get a type of existing objects and invoke its methods or access its fields and properties.
Update: Yes there are! I wrote a little rudimentary library, which can be downloaded here: http://automapper.nylle.de
Original answer: I haven't heard of it, but I assume this to be rather unlikely, since PHP does not support return types for methods or functions. How can you possibly map the properties of two different classes, if you can only reflect their names, but not their types?
You could still write a little static helper class that simply gets two flat objects and copies all values from one property to the other class' property with the same name using reflection, but this will only work, if you know what you do and the types are convertable (like scalar types string/int/bool).
Maybe you can put some more reliability into it by parsing the phpdoc
part (if available) to get a clue about the return type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With