ValueToSubValuesMapper
Expands a single bindable's value into multiple child ("sub") bindables. For each name => value in the resolved sub-values, it acquires a bindable at the descendant path <prop>/<name>, sets its value and marks it existing.
It is applied with logicalProp() (or logicalRoot()) so the child paths are exposed. The sub-values can be given as a static array or as a closure that receives the bindable's current value and returns an array.
This is the inverse of
Mappers::subMerge()(see SubMergeMapper), which reassembles descendant bindables back into a single value.
Example: expanding a value into sub props (closure)
$result = Bind::attrs(['prop1' => 'value1', 'prop2' => 'value2'])
->logicalProp('prop1', Mappers::valueToSubValues(fn (string $value) => [
'subProp1' => 'subValue1',
'subProp2' => 'subValue2',
]))
->prop('prop2')
->toArray()
->exec();
var_dump($result->get());
Output:
array(3) {
["prop1/subProp1"]=>
string(8) "subValue1"
["prop1/subProp2"]=>
string(8) "subValue2"
["prop2"]=>
string(6) "value2"
}
Example: static sub-values array
$result = Bind::attrs(['prop1' => 'value1', 'prop2' => 'value2'])
->logicalProp('prop1', Mappers::valueToSubValues([
'subProp1' => 'subValue1',
'subProp2' => 'subValue2',
]))
->prop('prop2')
->toArray()
->exec();
var_dump($result->get());
The output is identical to the closure form above.