You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-7Lines changed: 21 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,8 @@ This supposes we already created a mapping, `MyMapping`, to convert the data.
16
16
17
17
Mappings
18
18
--------
19
-
Mappings are data transformation descriptions that describe how to convert data from one format to another. Mapping classes are an object wrapper for an array that describes the output format with instructions (hereafter known as *strategies*) that fetch or augment input data. To write a mapping we must know the input data format so we can then write an array that represents the desired output format and decorate it with strategies.
19
+
20
+
Mappings are data transformation descriptions that describe how to convert data from one format to another. Mappings are an object wrapper for an array that describes the output format with instructions (hereafter known as *strategies*) that fetch or augment input data. To write a mapping we must know the input data format so we can then write an array that represents the desired output format and decorate it with strategies.
20
21
21
22
### Example
22
23
@@ -50,8 +51,9 @@ An expression is a pseudo-type representing the list of valid mapping value type
50
51
2.`Mapping`
51
52
3. Mapping fragment
52
53
4. Scalar
54
+
5.`null`
53
55
54
-
[Strategies](#strategies) are invoked and substituted as described in the following section. Mappings may contain any number of additional embedded mappings or mapping fragments—a mapping fragment is just a mapping described by an array instead of a `Mapping` object. Scalar values (*integer*, *float*, *string* and *boolean*) have no special meaning and are presented verbatim in the output.
56
+
[Strategies](#strategies) are invoked and substituted as described in the following section. Mappings may contain any number of additional embedded mappings or mapping fragments—a mapping fragment is just a mapping described by an array instead of a `Mapping` object. Scalar values (*integer*, *float*, *string* and *boolean*) and `null`have no special meaning and are presented verbatim in the output.
55
57
56
58
### Writing a mapping
57
59
@@ -68,9 +70,14 @@ Strategies are invokable classes that are invoked by Mapper and substituted for
68
70
69
71
Strategies are basic building blocks from which complex data manipulation chains can be constructed to meet the bespoke requirements of an application. The composition of strategies forms a powerful object composition DSL that allows us to express how to retrieve and augment data to mould it into the desired format.
70
72
71
-
### Core strategies
73
+
For a complete list of strategies please see the [strategy reference](#strategy-reference).
74
+
75
+
Strategy reference
76
+
------------------
77
+
78
+
The following strategies ship with Mapper and provide a suite of commonly used features, as listed below.
72
79
73
-
Core strategies are those that ship with Mapper and provide a suite of commonly used features, as listed below.
80
+
### Strategy index
74
81
75
82
#### Fetchers
76
83
@@ -80,7 +87,7 @@ Core strategies are those that ship with Mapper and provide a suite of commonly
80
87
#### Augmenters
81
88
82
89
-[Callback](#callback)– Augments data using the specified callback.
83
-
-[Collection](#collection)–Decorates a collection of data by applying a transformation to each datum.
90
+
-[Collection](#collection)–Maps a collection of data by applying a transformation to each datum.
84
91
-[Context](#context)– Replaces the context for the specified expression.
85
92
-[Either](#either)– Either uses the primary strategy, if it returns non-null, otherwise delegates to a fallback expression.
86
93
-[Filter](#filter)– Filters null values or values rejected by the specified callback.
@@ -189,7 +196,7 @@ Callback(callable $callback)
189
196
190
197
### Collection
191
198
192
-
Decorates a collection of data by applying a transformation to each datum using a callback. The data collection must be an expression that maps to an array otherwise null is returned.
199
+
Maps a collection of data by applying a transformation to each datum using a callback. The data collection must be an expression that maps to an array otherwise null is returned.
Strategies must implement the `Strategy` interface but it is common to extend `Delegate` or `Decorator` because we usually write augmenters which expect another strategy injected into them to provide data. `Delegate` and `Decorator` provide the `delegate()` method, which allows a strategy to evaluate an expression using Mapper, and is usually needed to evaluate the injected strategy. `Delegate` can delegate any expression to Mapper whereas `Decorator` only accepts `Strategy` objects.
525
532
526
-
It is recommended to name custom strategies with a *Strategy* suffix to help distinguish them from core strategies.
533
+
It is recommended to name custom strategies with a *Strategy* suffix to help distinguish them from stock strategies.
527
534
528
535
Requirements
529
536
------------
@@ -537,6 +544,13 @@ Testing
537
544
Mapper is fully unit tested. Run the tests with `bin/test` from a shell. All examples
538
545
in this document can be found in `DocumentationTest`.
539
546
547
+
Limitations
548
+
-----------
549
+
550
+
- Strategies do not know the name of the key they are assigned to because `Mapper` does not forward the key name.
551
+
- Strategies do not know where they sit in a `Mapping` and therefore cannot traverse a mapping relative to their position.
552
+
- The `Collection` strategy overwrites context making any previous context inaccessible to descendants.
0 commit comments