Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Why operator cast to lowercase ? #92

Open
Pierozi opened this issue Sep 14, 2016 · 4 comments
Open

Why operator cast to lowercase ? #92

Pierozi opened this issue Sep 14, 2016 · 4 comments

Comments

@Pierozi
Copy link
Member

Pierozi commented Sep 14, 2016

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 ?

@Hywan Hywan added the question label Sep 14, 2016
@Hywan Hywan self-assigned this Sep 14, 2016
@Hywan
Copy link
Member

Hywan commented Sep 14, 2016

Hello,

It means the language is case-insensitive.
I don't understand “why not rule”?

@Pierozi
Copy link
Member Author

Pierozi commented Sep 14, 2016

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;

@Hywan
Copy link
Member

Hywan commented Sep 14, 2016

What do you call a rule?

Indeed, setOperator should lowercase the operator. Do you want to make a PR?

@Pierozi
Copy link
Member Author

Pierozi commented Sep 14, 2016

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)
);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants