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
+19-66
Original file line number
Diff line number
Diff line change
@@ -39,11 +39,9 @@ Contents
39
39
1.[Merge](#merge)
40
40
1.[TakeFirst](#takefirst)
41
41
1.[ToList](#tolist)
42
-
1.[Translate](#translate)
43
42
1.[TryCatch](#trycatch)
44
43
1.[Type](#type)
45
44
1.[Unique](#unique)
46
-
1.[Walk](#walk)
47
45
1.[Others](#others)
48
46
1.[Debug](#debug)
49
47
1.[Requirements](#requirements)
@@ -287,7 +285,7 @@ The following strategies ship with Mapper and provide a suite of commonly used f
287
285
288
286
#### Fetchers
289
287
290
-
-[Copy](#copy)– Copies a portion of input data.
288
+
-[Copy](#copy)– Copies a portion of input data, or specified data, according to a lookup path.
291
289
-[CopyContext](#copycontext)– Copies a portion of context data.
292
290
-[CopyKey](#copykey)– Copies the current key.
293
291
@@ -305,29 +303,28 @@ The following strategies ship with Mapper and provide a suite of commonly used f
305
303
-[Merge](#merge)– Merges two data sets together giving precedence to the latter if keys collide.
306
304
-[TakeFirst](#takefirst)– Takes the first value from a collection one or more times.
307
305
-[ToList](#tolist)– Converts data to a single-element list unless it is already a list.
308
-
-[Translate](#translate)– Translates a value using a mapping.
309
306
-[TryCatch](#trycatch)– Tries the primary strategy and falls back to an expression if an exception is thrown.
310
307
-[Type](#type)– Casts data to the specified type.
311
308
-[Unique](#unique)– Creates a collection of unique values by removing duplicates.
312
-
-[Walk](#walk)– Walks a nested structure to the specified element in the same manner as `Copy`.
313
309
314
310
#### Others
315
311
316
312
-[Debug](#debug)– Debugs a mapping by breaking the debugger wherever this strategy is inserted.
317
313
318
314
### Copy
319
315
320
-
Copies a portion of the input dataaccording to the specified path. Supports traversing nested arrays.
316
+
Copies a portion of input data, or specified data, according to a lookup path. Supports traversing nested arrays.
321
317
322
-
`Copy` is probably the most common strategy whether used by itself or injected into other strategies.
318
+
`Copy` is probably the most common strategy whether used by itself or injected into other strategies. Since both its *path* and *data* parameters can be mapped expressions it is highly versatile and can be combined with other strategies, or even itself, to produce powerful expressions.
1.`$value`– Value used to match against an entry in the mapping.
786
-
2.`$mapping`– Mapping that specifies what the value may be translated to.
787
-
788
-
#### Example
789
-
790
-
```php
791
-
(new Mapper)->map(
792
-
['foo' => 'foo'],
793
-
new Translate(
794
-
new Copy('foo'),
795
-
['foo' => 'bar']
796
-
)
797
-
);
798
-
```
799
-
800
-
> 'bar'
801
-
802
785
### TryCatch
803
786
804
787
Tries the primary strategy and falls back to an expression if an exception is thrown. The thrown exception is passed to the specified exception handler. The handler should throw an exception if it does not expect the exception type it receives.
2.`$path`– Array of path components, string of `->`-delimited path components or a strategy or mapping resolving to such an expression.
897
-
898
-
#### Example
899
-
900
-
```php
901
-
(new Mapper)->map(
902
-
[
903
-
'foo' => [
904
-
'bar' => [
905
-
'baz' => 123,
906
-
],
907
-
],
908
-
],
909
-
new Walk(new Copy('foo'), 'bar->baz')
910
-
)
911
-
```
912
-
913
-
> 123
914
-
915
868
### Debug
916
869
917
870
Debugs a mapping by breaking the debugger wherever this strategy is inserted. The specified expression will be mapped immediately before triggering the breakpoint. The debugger should see the current data, context and mapped expression.
0 commit comments