-
Notifications
You must be signed in to change notification settings - Fork 0
Belt
A. B. M. Mahmudul Hasan edited this page Apr 11, 2022
·
2 revisions
You will get all the functionalities of Arrject here. Additionally you will also get some logical setter & getter.
$myArray = [];
$belt = new \AbmmHasan\Bucket\Functional\Belt($myArray);
// Set on Get function (will be applied during get)
$belt->onGet("greet", function ($value) {
return trim($value);
});
// set on Set function (will be applied during Set)
$belt->onSet("email", function ($value) {
if (!filter_var($value, FILTER_VALIDATE_EMAIL)){
throw new \Exception("Invalid email can't be set");
}
return filter_var($value, FILTER_SANITIZE_EMAIL);
});
// on Get example
$belt->greet = ' hello';
echo $belt->greet; // output: 'hello'
//on Set example
$belt->email = 'abc.com'; // will throw exception during set, as it is invalid Email address