Skip to main content

SubPropsMapper

Defines a sub-mapping plan for the children of a bindable. Mappers::subProps() returns a composer exposing the same ->prop(...), ->props(...) and ->logicalProp(...) methods as Bind, so you can map individual child properties of a structured (array / DataMap) value.

It is applied with logicalProp() — or logicalRoot() at the top level of a bind — which exposes the bindable's children to the sub-plan. Only the props declared in the sub-plan are mapped; other children are ignored.

Mappers::subPropsForClass($class) auto-declares the props from a class's properties, and Mappers::subMerge() / Mappers::subMergeToObject() merge the mapped children back into an array or object. Together these power ObjectUnmarshalTrait — see UnmarshalMapper.

Example: mapping nested properties​

$src = new DataMap(['sub' => ['huii' => 'bar', 'ignored' => '!!']]);
$target = new DataMap();

Bind::attrs($src)->toAttrs($target)
->logicalProp('sub', Mappers::subProps()
->prop('huii', Mappers::value(fn ($v) => $v . '2')))
->exec();

echo $target->req('sub/huii'); // bar2
// 'sub/ignored' is not mapped.

Example: logicalRoot and nested subProps​

$src = new DataMap(['holeradio' => 'foo', 'ignored' => '!!', 'sub' => ['huii' => 'bar', 'ignored' => '!!']]);
$target = new DataMap();

Bind::attrs($src)->toAttrs($target)
->logicalRoot(Mappers::subProps()
->prop('holeradio', Mappers::value(fn ($v) => $v . '2'))
->logicalProp('sub', Mappers::subProps()
->prop('huii', Mappers::value(fn ($v) => $v . '2'))))
->exec();

echo $target->req('holeradio'); // foo2
echo $target->req('sub/huii'); // bar2
// 'ignored' and 'sub/ignored' are not mapped.