FactoryClosureMapper
Builds a mapper dynamically at bind time. The closure receives the BindBoundary and BindContext (injectable by type hint) and returns a Mapper, which is then run against the current bindables. Returning null leaves the bindables unchanged.
This lets you choose mappers based on other values in the bind context — e.g. a validation range taken from a sibling prop.
Example: choosing a mapper from a sibling value
$target = new DataMap();
Bind::attrs(['minNum' => 2, 'maxNum' => 4])->toAttrs($target)
->optProp('maxNum', Mappers::factoryClosure(function (BindContext $bindContext) {
$minNum = $bindContext->getValue('minNum');
return Mappers::value(fn (int $maxNum) => $maxNum + 1);
}))
->optProp('minNum', Mappers::int())
->exec();
var_dump($target->toArray());
Output:
array(2) {
["minNum"]=>
int(2)
["maxNum"]=>
int(5)
}
The factory closure reads minNum from the context and returns a value mapper that increments maxNum. If the closure returns null, maxNum passes through unchanged.