Repository navigation
Callbacks
github-actions[bot] edited this page Oct 5, 2026
·
1 revision
The optional third argument of Mapper::map() receives every result entry and
returns the value to store.
$result = Mapper::map($data, $schema, function ($key, $value) {
if ($key === 'email') {
return strtolower($value);
}
return $value;
});- Arguments: the result key (
stringorint) and the mapped value. - The key of a collection is passed without the
[]suffix. - Nested schemas are processed first: the callback sees each child entry, then the parent key with the already transformed array.
- For a collection, the callback sees each column (a list) and then the merged rows.
- Any callable works: closures, function names,
[ClassName::class, 'method']and invokable objects.
// Schema: ['id' => '@data/id', 'lines[]' => ['sku' => '@data/items/*/sku']]
// Calls, in order:
// ('id', 10)
// ('sku', ['A', 'B'])
// ('lines', [['sku' => 'A'], ['sku' => 'B']])- Always return
$valuefor keys you do not change. - Key names can repeat at different levels. Check the value type as well as the key when that matters.
- A schema with integer keys passes integers to the callback. Declare the key
parameter without a type, or as
int|stringon PHP 8, when you use such schemas.
Dalue is licensed under GPL-3.0-or-later. Source: uuur86/dalue · Edit these pages in docs/wiki.