In our current application I have a report that contains something like:
if($foo == 3 || $bar > 3) {
$e = someFunction();
};
but for a different client that same expression might be:
if($foo == 3 || $bar == 5 && $foobar != 9) {
$e = someFunction();
};
Is there an straight-forward way to store the two different expressions, just the
$foo == 3 || $bar > 3 OR $foo == 3 || $bar == 5
bits in the database (MySQL) so I do not have to hard code all of these rules by client or maintain client versions of the same report. I’m trying to figure out if I can set a variable o replace the conditions. Something like:
$conditions = $row_rsConditions['condition_row'] //Get $foo == 3 || $bar > 3 from the DB and store it as $conditions
if($conditions) {
$e = someFunction();
};
There could be > 100 different clients and each client could/would have a different set of expressions.
I’m just not sure of the right/best way to do this.
UPDATE:
I think I understand the issues using PHP’s eval() function. But because of the number of possible combinations I am leaning towards using the DB to store the conditions (not sure about using eval() just yet)
Does it make any difference (safer) if there is no user facing interface that writes to the condition field/table? It could be something we manage on our end alone.
i would be very careful about storing logic in the database.
this might not be the best solution
but i would suggest creating an abstract base class, then inherit from that, a class specific to each client.
Any functions that are customised can be added as a method to the base class, and overridden for client specific implementation.
use a switch statement to instantiate the class based on a client id or name (something that doesn’t change) that you already store in the database.