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
+53-21Lines changed: 53 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,28 +19,29 @@ Contents
19
19
--------
20
20
21
21
1.[Mappings](#mappings)
22
-
2.[Strategies](#strategies)
23
-
3.[Practical example](#practical-example)
24
-
4.[Strategy reference](#strategy-reference)
22
+
1.[Strategies](#strategies)
23
+
1.[Practical example](#practical-example)
24
+
1.[Strategy reference](#strategy-reference)
25
25
1.[Copy](#copy)
26
-
2.[CopyContext](#copycontext)
27
-
3.[Callback](#callback)
28
-
4.[Collection](#collection)
29
-
5.[Context](#context)
30
-
6.[Either](#either)
31
-
7.[Filter](#filter)
32
-
8.[Flatten](#flatten)
33
-
9.[IfExists](#ifexists)
34
-
10.[Merge](#merge)
35
-
11.[TakeFirst](#takefirst)
36
-
12.[ToList](#tolist)
37
-
13.[TryCatch](#trycatch)
38
-
14.[Type](#type)
39
-
15.[Unique](#unique)
40
-
16.[Walk](#walk)
41
-
5.[Requirements](#requirements)
42
-
6.[Limitations](#limitations)
43
-
7.[Testing](#testing)
26
+
1.[CopyContext](#copycontext)
27
+
1.[CopyKey](#copykey)
28
+
1.[Callback](#callback)
29
+
1.[Collection](#collection)
30
+
1.[Context](#context)
31
+
1.[Either](#either)
32
+
1.[Filter](#filter)
33
+
1.[Flatten](#flatten)
34
+
1.[IfExists](#ifexists)
35
+
1.[Merge](#merge)
36
+
1.[TakeFirst](#takefirst)
37
+
1.[ToList](#tolist)
38
+
1.[TryCatch](#trycatch)
39
+
1.[Type](#type)
40
+
1.[Unique](#unique)
41
+
1.[Walk](#walk)
42
+
1.[Requirements](#requirements)
43
+
1.[Limitations](#limitations)
44
+
1.[Testing](#testing)
44
45
45
46
Mappings
46
47
--------
@@ -281,6 +282,7 @@ The following strategies ship with Mapper and provide a suite of commonly used f
281
282
282
283
-[Copy](#copy)– Copies a portion of input data.
283
284
-[CopyContext](#copycontext)– Copies a portion of context data.
285
+
-[CopyKey](#copykey)– Copies the current key.
284
286
285
287
#### Augmenters
286
288
@@ -358,6 +360,34 @@ $context = ['foo' => 456];
358
360
359
361
> 456
360
362
363
+
### CopyKey
364
+
365
+
Copies the current key from the key context. This strategy requires the key context to be set by another strategy. By default the key context is `null`. Currently only the [collection strategy](#collection) sets a key context.
366
+
367
+
#### Signature
368
+
369
+
```php
370
+
CopyKey()
371
+
```
372
+
373
+
#### Example
374
+
375
+
```php
376
+
(new Mapper)->map(
377
+
[
378
+
'foo' => [
379
+
'bar' => 'baz',
380
+
],
381
+
],
382
+
new Collection(
383
+
new Copy('foo'),
384
+
new CopyKey
385
+
)
386
+
)
387
+
```
388
+
389
+
> ['bar' => 'bar']
390
+
361
391
### Callback
362
392
363
393
Augments data using the return value of the specified callback.
@@ -397,6 +427,8 @@ Callback(callable $callback)
397
427
398
428
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.
399
429
430
+
For each item in the collection, this strategy sets the context to the current datum and the key context to the current key, which can be retrieved using [CopyKey](#copykey).
0 commit comments