What I'm trying to do is create a Web based rules engine where users can create conditional statements, store them in a db, then execute them on a dataset. (E.g., If color equals green, then append something to description)
So what I'm thinking is using a JavaScript front-end rules builder (https://github.com/joshuamcginnis/rules-builder) to build an expression in JSON, and store that command expression in MongoDB.
Now when those rules need executed, they get pulled from the DB, and built and executed via Ruler - A stateless PHP rules engine (https://github.com/bobthecow/Ruler)
So the missing piece for me is how I can translate the JSON command into a chained PHP command that Ruler understands? Is there a design pattern that addresses something like this?
So this sounds like you're going to have to write a parser (or interpreter), one that can evaluate commands such as equal
and equalOrGreaterThan
or short synax =
and >=
from the JSON file and build the expressions based of these commands.
Take a look at this link http://www.slideshare.net/relaxnow/lets-build-a-parser, it will give you some insight into what I mean. I wish I could quote it but its a slide show.