Skip to main content
11 events
when toggle format what by license comment
Mar 24, 2019 at 12:38 vote accept oliverbj
Mar 22, 2019 at 1:51 comment added Hieu Le You can change the signature of the apply method to apply($text, $options) to remove the parameters from rule classes constructors. Then, create a singleton for each rule. When you need a rule instance, retrieve the singleton, pass the text and the options to the new apply method. With this approach, you only need one instance for each rule class.
Mar 21, 2019 at 15:33 comment added oliverbj Thanks! But if I need to apply let’s say 10 rules, it won’t be a problem that I need to loop through 10 different classes, in order to add it to the $rules array?
Mar 21, 2019 at 1:40 comment added Hieu Le Hi @oliverbj, I updated my answer. Hope this help.
Mar 21, 2019 at 1:40 history edited Hieu Le CC BY-SA 4.0
added 635 characters in body
Mar 20, 2019 at 14:02 comment added oliverbj can you please show an example on how to actually use the interfaces? Say I have created a class called ApplyParsingRules.php, which will be called whenever a new text document is avaialble to be parsed (and rules are available). How can I dynamically apply all the rules from the database?
Mar 20, 2019 at 7:16 comment added Hieu Le For example, we have rule #1 (order = 1), rule #2 (order = 2), rule #3 (order = 3). When user deletes rule #2, we should update the order of other rules. So, the order of rule #3 will be set to 2 before being saved to the database.
Mar 20, 2019 at 7:03 comment added oliverbj But parsing_rules should be dynamic and users should be able to apply these to different documents. Further, each parsing rule will be unique to the specific stream
Mar 20, 2019 at 6:23 comment added Hieu Le When we update the list of rules, we should re-calculate the orders of rules and update them. I don't think we should allow user to delete a rules from database directly.
Mar 20, 2019 at 5:34 comment added oliverbj This makes sense. Really like the “order” column. Hadn’t thought about that. A follow up question: what if for example, an user deletes rule #3 - how would that be reflected in the database? Because then rule 4 -> rule ->3
Mar 20, 2019 at 2:12 history answered Hieu Le CC BY-SA 4.0