1 | <?php |
||
17 | trait Mappers |
||
18 | { |
||
19 | /** |
||
20 | * @var Mapper[] list of Mappers |
||
21 | */ |
||
22 | protected $mappers = []; |
||
23 | |||
24 | /** |
||
25 | * @var Indexer|null |
||
26 | */ |
||
27 | protected $indexer; |
||
28 | |||
29 | /** |
||
30 | * Append a Mapper instance to apply when each batch of a record-set is fetched. |
||
31 | * |
||
32 | * @param Mapper $mapper |
||
33 | * |
||
34 | * @see mapRecords() to map an anonymous function against every record |
||
35 | * @see mapBatches() to map an anonymous function against each batch of records |
||
36 | * |
||
37 | * @return $this |
||
38 | */ |
||
39 | public function map(Mapper $mapper) |
||
45 | |||
46 | /** |
||
47 | * Map an anonymous function against every record. |
||
48 | * |
||
49 | * @param callable $mapper function (mixed $record) : mixed |
||
50 | * |
||
51 | * @see mapBatches() to map an anonymous function against each batch of records |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | 1 | public function mapRecords(callable $mapper) |
|
61 | |||
62 | /** |
||
63 | * Map an anonymous function against each batch of records. |
||
64 | * |
||
65 | * @param callable $mapper function (array $record_set) : array |
||
66 | * |
||
67 | * @see mapRecords() to map an anonymous function against every record |
||
68 | * |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function mapBatches(callable $mapper) |
||
77 | |||
78 | /** |
||
79 | * Define an {@see Indexer}, callable, Column, or Column-name to use |
||
80 | * to compute an index-value for the returned records. |
||
81 | * |
||
82 | * Note that this can lead to index-collisions - for example, using a foreign key |
||
83 | * in a query with multiple records for the same foreign key, may cause the same |
||
84 | * foreign key to occur as an index multiple times; this will cause a run-time |
||
85 | * exception when calling e.g. {@see Result::all()}. |
||
86 | * |
||
87 | * Note that iterating over the `Result` instance directly (and *not* calling the |
||
88 | * `all()` method) does permit iteration over results with duplicate indices - this |
||
89 | * can be useful e.g. when collecting child records to append to a parent. |
||
90 | * |
||
91 | * @param Indexer|Column|callable|string $indexer |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | 1 | public function index($indexer) |
|
111 | } |
||
112 |