0

This is one of those wishy-washy questions but hopefully will lead to some good answers as I think the issues comes up often. I am building a subscription based platform/site where people are able to setup their own services with unique rules. There are millions of combinations of these rules that make up the essence of a specific subscription.

For example: A dude owns some club and sets up a service with a rule that allows any member to access facilities only once a day, thereafter access is denied. A user subscribed to that service will have these rules imposed on him/her. Is there a clean way to make this configurable without over-engineering it?

Some of the options I have considered:

  • Hierarchical database acting as a decision tree.

  • Saving rules in a table like [id, name, expression, value] where the expression could be a set of well defined operators or even regex and the value would be used in testing against input. eg: [1, visitations, < , 20] some fancy (and probably very unsave eval code can then be used to resolve the rule)

  • bobthecow/Ruler

Anyways, just in case there are specific implementations for this kind of problem, i'm using php with the laravel framework.

cmptrwizard
  • 338
  • 4
  • 9
  • If there's a package (bobthecow/ruler) why not use it? Is something wrong about it? – lukasgeiter Jan 19 '15 at 08:24
  • It looks pretty neat but what would be the best way to make it configurable? How would I "save" rules and make it config driven instead of code driven? – cmptrwizard Jan 19 '15 at 08:43
  • I don't know the package and I have only looked at it for 10 seconds, but if I where you I would install it, spend some quality time with it and try to figure out how you might extend/change it to fit your needs... – lukasgeiter Jan 19 '15 at 08:46
  • Not good DB design, but you can store json configurations in that table – Royal Bg Jan 19 '15 at 08:49
  • Please don't store JSON in your db! – lukasgeiter Jan 19 '15 at 09:03
  • @lukasgeiter sometimes it's needed, when you don't know what the input will be. This is the way how many abstract application like CMS's work. It's far from good design, the other way is to predict all possible variations. Which, honestly, sometimes is not possible. – Royal Bg Jan 19 '15 at 09:07
  • @RoyalBg You don't necessarily need to predict all possible variations. You can already do a lot of dynamic things with just an EAV setup. (Not saying that EAV is the solution for this question ;)) – lukasgeiter Jan 19 '15 at 09:10
  • I am leaning towards an EAV model since some of my entities already follow that pattern but it still feels hacky to build a rules engine on that? – cmptrwizard Jan 19 '15 at 12:29

0 Answers0