AutoMapper can map data from array/object to existing array/object or marshal a new one.
Mapping rules specified in declarative way using three simple definitions:
- From definition (
From::createor via short functionfrom) — maps single field from source to target. Supports chainable functions:
->convert(callable $callable)— converts input value to another one via any callable;->trim()— trims value to eliminate whitespaces (suitable for strings);->default($defaultValue)— returns default value if source field is missing;->ignoreMissing()— ignores target field if source field is missing;->ignoreEmpty()— ignores target field if source field is empty.- Aggregate definition (
Aggregate::createor via short functionaggregate) — maps multiple fields from source to single target field. Supports chainable functions:
->trim()— trims aggregated value->ignoreEmpty()— ignores target field if aggregated value is empty.- Value definition (
Value::createor via short functionvalue) — maps constant value to target field. Supports chainable functions:
->trim()->ignoreEmpty()All missing source fields can be ignored via
AutoMapper::create(...)->ignoreAllMissing()modifier.