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 has been archived by the owner on Sep 20, 2021. It is now read-only.
Ruler is well designed for writing rules and making assertions on them (i.e checking if some input validates the rule).
An nice feature would to be able to produce any result in response of these assertions (i.e if some input validates a rule then the engine should provide us a value).
Let's take a simple example:
If I'm at least 16 years old, I can buy beer
If I'm at least 18 years old, I can buy whiskey, gin or vodka
Hoa\Ruler\Rules is a collection of rules, ordered by a priority,
it has a add(string $id, Rule $rule, int $priority) method,
the $id lets us reuse the rule result in following rules,
the $rule is a standard ruler rule (a string or a compiled rule) wrapped in a Then or ThenElse class,
the $priority is used to order the collection (higher priority will run first);
we can ask for the best results (getBestResult) which will be the result of the higher priority rule validating the context,
we can ask for all results (getAllResults) of valid rules
This kind of feature will allow for more generic code when it comes to work with rules and produce results depending on them.
The Rules collection can easily be built with results coming from a database.
What has to be done:
Implement the Rules collection (first with an SplPriorityQueue and then with the hoa/heap library)
Implement the Then rule class (it returns a result when the rule validates the input)
Implement the ThenElse rule class (it returns a result when the rule validates the input and another when the rule does not validate the input)
Implement an algorithm to resolve rules dependencies (indeed, a rule can depend on another one). hoa/graph could be a good candidate for this kind of work.
Implement a rule() function to reference the result of one rule from another rule
Let me know if I forgot something. I have a working POC which needs some cleanup.
The text was updated successfully, but these errors were encountered:
Hywan
changed the title
Produce results in response of rules evaluation
Produce results in response of rule evaluations
Sep 14, 2016
Ruler is well designed for writing rules and making assertions on them (i.e checking if some input validates the rule).
An nice feature would to be able to produce any result in response of these assertions (i.e if some input validates a rule then the engine should provide us a value).
Let's take a simple example:
With only ruler, I would have to write two rules:
$r1 = 'person.age >= 16'
$r2 = 'person.age >= 18'
And some PHP code:
This is not really efficient: the more rules I have, the more code I need to write. If the results change, I'll have to change my PHP code, ...
What I propose here is something more flexible:
Let me explain:
Hoa\Ruler\Rules
is a collection of rules, ordered by a priority,add(string $id, Rule $rule, int $priority)
method,$id
lets us reuse the rule result in following rules,$rule
is a standard ruler rule (a string or a compiled rule) wrapped in aThen
orThenElse
class,$priority
is used to order the collection (higher priority will run first);getBestResult
) which will be the result of the higher priority rule validating the context,getAllResults
) of valid rulesThis kind of feature will allow for more generic code when it comes to work with rules and produce results depending on them.
The
Rules
collection can easily be built with results coming from a database.What has to be done:
Rules
collection (first with anSplPriorityQueue
and then with thehoa/heap
library)Then
rule class (it returns a result when the rule validates the input)ThenElse
rule class (it returns a result when the rule validates the input and another when the rule does not validate the input)hoa/graph
could be a good candidate for this kind of work.rule()
function to reference the result of one rule from another ruleLet me know if I forgot something. I have a working POC which needs some cleanup.
The text was updated successfully, but these errors were encountered: