Skip to main content

BindablesClosureMapper

The lowest-level escape hatch: hands the raw Bindable objects of the current boundary to a closure so it can mutate them directly — set values, flip existence, or acquire new bindables via the BindBoundary. The closure does all the work; the mapper just wraps the result.

The closure receives an array of Bindable objects (keyed by name) and may type-hint BindBoundary as an additional parameter. It should return a bool (returning false aborts the bind); omitting the return treats it as success.

Mappers::bindables() and Mappers::closure() are aliases. Mappers::bindablesClosure() is a deprecated alias.

This is the most powerful closure mapper but bypasses the value/transform conveniences of the others. Prefer Mappers::values() when you only need to read and write values, or Mappers::value() / Mappers::bindable() for single-bindable work.

Example: mutating bindables directly​

$target = new DataMap();
Bind::attrs(['string' => 'test', 'int' => 321])->toAttrs($target)
->props(['string', 'int'], Mappers::bindables(function (array $bindables, BindBoundary $bindBoundary) {
$bindables['string']->setValue('huii');
$bindables['int']->setExist(false);
$bindBoundary->acquireBindable('superInt')->setExist(true)->setValue(123);
}))
->exec();
var_dump($target->toArray());

Output:

array(2) {
["string"]=>
string(4) "huii"
["superInt"]=>
int(123)
}

string is rewritten, int is dropped (setExist(false)), and a brand-new superInt bindable is acquired and written.