Mapping Table
When we tell the mapper to map a source to a target, it will look up the mapping table to find the correct transformer for the job, then tells the transformer to do the mapping. It does that first for the root source and target pair, then traverses down the properties and does the same for each property.
Each transformer supplies a list of supported source to target mappings. The mapping table is constructed from the source and target types supported by each of the transformers registered in the system.
Mapping Table Properties
A row in the mapping table has the following properties:
- Ordering number. Transformers have a priority. A mapping entry generated by a transformer with a higher priority will be checked earlier than those generated by one with a lower priority.
- Source and target type pair.
- Target variance. Invariant means the target type must be exactly the same as specified in the mapping table. Variant means the target type can also be a subclass of the type specified in the mapping table. Note that the source type is always variant.
- Transformer service ID.
Viewing the Mapping Table
To inspect the mapping table, you can use the rekalogika:mapper:mapping
command:
$ php bin/console rekalogika:mapper:mapping
The Mapper panel of the Symfony Profiler also shows the mapping table.
Default Mapping Table
Ordering | Source Type | Target Type | Target Variance | Class |
---|---|---|---|---|
1 | null | null | invariant | NullToNullTransformer |
2 | int | int | invariant | ScalarToScalarTransformer |
3 | int | float | invariant | ScalarToScalarTransformer |
4 | int | string | invariant | ScalarToScalarTransformer |
5 | int | bool | invariant | ScalarToScalarTransformer |
6 | float | int | invariant | ScalarToScalarTransformer |
7 | float | float | invariant | ScalarToScalarTransformer |
8 | float | string | invariant | ScalarToScalarTransformer |
9 | float | bool | invariant | ScalarToScalarTransformer |
10 | string | int | invariant | ScalarToScalarTransformer |
11 | string | float | invariant | ScalarToScalarTransformer |
12 | string | string | invariant | ScalarToScalarTransformer |
13 | string | bool | invariant | ScalarToScalarTransformer |
14 | bool | int | invariant | ScalarToScalarTransformer |
15 | bool | float | invariant | ScalarToScalarTransformer |
16 | bool | string | invariant | ScalarToScalarTransformer |
17 | bool | bool | invariant | ScalarToScalarTransformer |
18 | string | DateTimeInterface | invariant | DateTimeTransformer |
19 | string | DateTime | invariant | DateTimeTransformer |
20 | string | DateTimeImmutable | invariant | DateTimeTransformer |
21 | string | DatePoint | invariant | DateTimeTransformer |
22 | DateTimeInterface | DateTimeInterface | invariant | DateTimeTransformer |
23 | DateTimeInterface | DateTime | invariant | DateTimeTransformer |
24 | DateTimeInterface | DateTimeImmutable | invariant | DateTimeTransformer |
25 | DateTimeInterface | DatePoint | invariant | DateTimeTransformer |
26 | DateTimeInterface | string | invariant | DateTimeTransformer |
27 | string | BackedEnum | variant | StringToBackedEnumTransformer |
28 | MapToObjectInterface | object | variant | ClassMethodTransformer |
29 | object | MapFromObjectInterface | variant | ClassMethodTransformer |
30 | Stringable | string | invariant | ObjectToStringTransformer |
31 | UnitEnum | string | invariant | ObjectToStringTransformer |
32 | Traversable | Collection | invariant | TraversableToArrayAccessTransformer |
33 | Traversable | ReadableCollection | invariant | TraversableToArrayAccessTransformer |
34 | Traversable | ArrayCollection | invariant | TraversableToArrayAccessTransformer |
35 | Traversable | ArrayObject | invariant | TraversableToArrayAccessTransformer |
36 | Traversable | ArrayIterator | invariant | TraversableToArrayAccessTransformer |
37 | Traversable | ArrayAccess | invariant | TraversableToArrayAccessTransformer |
38 | Traversable | CollectionInterface | invariant | TraversableToArrayAccessTransformer |
39 | Traversable | array | invariant | TraversableToArrayAccessTransformer |
40 | array | Collection | invariant | TraversableToArrayAccessTransformer |
41 | array | ReadableCollection | invariant | TraversableToArrayAccessTransformer |
42 | array | ArrayCollection | invariant | TraversableToArrayAccessTransformer |
43 | array | ArrayObject | invariant | TraversableToArrayAccessTransformer |
44 | array | ArrayIterator | invariant | TraversableToArrayAccessTransformer |
45 | array | ArrayAccess | invariant | TraversableToArrayAccessTransformer |
46 | array | CollectionInterface | invariant | TraversableToArrayAccessTransformer |
47 | array | array | invariant | TraversableToArrayAccessTransformer |
48 | Traversable | Traversable | invariant | TraversableToTraversableTransformer |
49 | array | Traversable | invariant | TraversableToTraversableTransformer |
50 | object | array | invariant | ObjectToArrayTransformer |
51 | array | object | variant | ArrayToObjectTransformer |
52 | object | object | variant | ObjectToObjectTransformer |
53 | null | string | invariant | NullTransformer |
54 | null | int | invariant | NullTransformer |
55 | null | float | invariant | NullTransformer |
56 | null | bool | invariant | NullTransformer |
57 | null | array | invariant | NullTransformer |
58 | mixed | null | invariant | NullTransformer |
59 | mixed | mixed | variant | CopyTransformer |