-
Notifications
You must be signed in to change notification settings - Fork 66
Produce results in response of rule evaluations #95
base: master
Are you sure you want to change the base?
Conversation
@jubianchi Tell me when you need a review. |
@Hywan you can start reviewing when you want: any comment is good. There are still some things to do but I'd be glad to fix any issue you already saw ;) |
ping? |
@jubianchi I am interested in this feature as well. Is there anything I can help you with? |
I can finish this issue if someone can give me:
With that I would be able to ship new code and fix everything you spotted in a single iteration. TBH I won't have time to come back here after every push so I'd rather do everything in a single iteration. |
Hi, I took a look at the code because it seems similar to something I'm looking for. afaict, this PR provides classes to associate a result with a rule (Then & ThenElse) and a class to get the first valid result of a set of rules. $rule = 'apply_discount(price, if(premium, 0.9, 1))';
$ruler = new Hoa\Ruler\Ruler();
$context = new Hoa\Ruler\Context();
$context['user'] = true;
$context['product'] = '100';
// add apply_discount
assert($ruler->execute($rule, $context) === '90'); is this out of the scope of this PR ? |
1 similar comment
@jubianchi Should we do another round review? |
@Hywan yes you can if you think this feature really makes sense in Ruler. I was asking myself if it should stay here or go somewhere else... BTW I updated the PR to use hoa/heap instead of SplHeap as requested in previous discussions. |
See #94 for detailed information.
Todo:
Rules
collection with anSplPriorityQueue
hoa/heap
library for theRules
collectionThen
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 ruleSome notes about the technical choices:
clone
s in the code: this is to guarantee immutability of the passed objects. For example theHoa\Ruler\Rules::initializeRuler()
may alter the ruler's asserter. Before doing this, we clone the ruler and then alter its content. Finally we return it to be used where needed.Hoa\Ruler\Result
class (with a magic method: this will change). It also does aclone
of the result in some cases: this is to avoid mutating the value returned by the rules.Hoa\Ruler\Result
) is also here to return a structured result letting developers keep track of the returned value, the rule that produced it and its name in the collection