You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 20, 2021. It is now read-only.
// The User object.class User {
constDISCONNECTED = 0;
constCONNECTED = 1;
public$group = 'customer';
public$points = 42;
protected$_status = 0;
publicfunctiongetStatus ( ) {
return$this->_status;
}
}
$ruler = newHoa\Ruler\Ruler();
// New rule.$rule = 'logged(user) and group in ["customer", "guest"] and points > 30';
// New context.$context = newHoa\Ruler\Context();
$context['user'] = function ( ) use ( $context ) {
$user = newUser();
$context['group'] = $user->group;
$context['points'] = $user->points;
return$user;
};
// We add the logged() operator.$ruler->getDefaultAsserter()->setOperator('logged', function ( User$user ) {
return$user::CONNECTED === $user->getStatus();
});
// Finally, we assert the rule.var_dump(
$ruler->assert($rule, $context)
);
/** * Will output: * bool(false) */
Ok so we have here a rule not respected, but why this rule doesn't passed is it because we have the user logout or because them points is <= 30
It could be useful to identify the reason of breaking rules. But all rules depends on operator so I think the operator could provide a property with error message when the result of validation is false and aggregate in ruler to got it.
To continue the example above
var_dump(
$ruler->getErrorMessages();
);
/** * Will output: * array( * 'User is not logged' * ) */
Take an example
Ok so we have here a rule not respected, but why this rule doesn't passed is it because we have the user logout or because them points is <= 30
It could be useful to identify the reason of breaking rules. But all rules depends on operator so I think the operator could provide a property with error message when the result of validation is false and aggregate in ruler to got it.
To continue the example above
What do you think ?