ℹ️ You are on a branch with the second version of the acelot/automapper.
If you want a previous version, then proceed to 1.x branch., (*1)
, (*2)
, (*3)
AutoMapper is a powerful declarative data mapper for PHP 8.
AutoMapper can map data from any source data (usually array/object) to the existing array/object or marshal a new ones., (*4)
No need to use concrete classes, it's better to use the AutoMapper API static functions.
It is very convenient to import the AutoMapper as a short alias, for example use Acelot\AutoMapper\AutoMapper as a., (*8)
Iterates over elements of an iterable and applies the given sub-processor. ℹ️ Produces values by yield operator, so in order to retrieve them you should to iterate the result or call toArray helper.
Conveyor processor. Accepts multiple sub-processors and pass the value to the first sub-processor, then pass the result of the first to the second, then to the third and so on.
Helpers are the processors that built on top of the another processors. Some helpers are just a shorthands to the core processors with specific arguments, some of them are combination of the multiple processors., (*12)
Converts the incoming value to string type. Throws UnexpectedValueException if incoming value is not a scalar or an object that not implements __toString.
The Context is a special DTO class for storing any kind of data: configs, DB connections, fixtures, etc.
This DTO is passed to the mapper, and you can use your data inside the processors.
Processors capable of working with the context end with Ctx suffix, callCtx for example., (*13)
How to use get processor?
You can obtain any key/prop/method from the source using the get processor which accepts a special path string.
The processor parses the given path and divides it into parts, then pulls out the data following the parts of the path., (*14)
Available path parts:, (*15)
Part
Description
@
"Self Pointer" – returns the source itself
[0]
Returns an array value by index
[key]
Returns an array value by key
[some key]
Returns an array value by key with spaces
[#first]
Returns an array first value
[#last]
Returns an array last value
->property
Returns an object value by property
->{some property}
Returns an object value by property name with spaces
->someMethod()
Calls an object method and returns the value
You can combine the parts to obtain the deep values:, (*16)
[array_key][array key with spaces][#first][#last]->property->{property with spaces}->someMethod()
If any part of the path is not found, then the processor will return NotFoundValue value.
This value throws an NotFoundException but you can recover it using ifNotFound helper., (*17)
🖋️ License
Licensed under MIT. Copyright (c) 2017-present, Valeriy Protopopov, (*18)