Skip to content
A. B. M. Mahmudul Hasan edited this page Apr 11, 2022 · 2 revisions

Something different?

You will get all the functionalities of Arrject here. Additionally you will also get some logical setter & getter.

Some example and explanation

$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
Clone this wiki locally