Why operator cast to lowercase ?
Pierozi opened this issue · 4 comments
Hello,
I trying a rule with camelcase operator and discover the Ruler\Model cast to lowercase.
Business logic term may want use native language of business with long name like :
produitBloquerEnRetail(product)
vs produitbloquerenretail(product)
produitAlternatifEnStock(product)
vs produitalternatifenstock(product)
https://github.com/hoaproject/Ruler/blob/master/Model/Model.php#L140
return new Operator(mb_strtolower($name), $arguments, $isFunction);
Easy resolve by casting rule to lower, but if operator are cast, why not rule ?
Hello,
It means the language is case-insensitive.
I don't understand “why not rule”?
Sorry, just check it, and is the value give to Asserter::setOperator()
must be lowercase, because then the model look it by casting to lowercase.
Rule can be keep in case-insensitive, but operator not.
In this case we should cast to lower too for keep it case-insensitive no ?
https://github.com/hoaproject/Ruler/blob/master/Visitor/Asserter.php#L468
$this->_operators[$operator] = $callable;
What do you call a rule?
Indeed, setOperator
should lowercase the operator. Do you want to make a PR?
Rule is rule 😄 logged(user) and group in ["customer", "guest"] and points > 30
Yep i will write PR right now.
There is MWE
$ruler = new Hoa\Ruler\Ruler();
$context = new Hoa\Ruler\Context();
$context['project'] = 'hoa';
$ruler->getDefaultAsserter()->setOperator('isAwesomeProject', function ($project) {
return 'hoa' === $project;
});
var_dump(
$ruler->assert('isAwesomeProject(project)', $context)
);