Question:
I need to develop an application that fits several projects with common features, however each one has several specific rules.
What I need is a structure that allows me to easily change these rules, in this case I chose to save the rules in the database and use the eval()
function to execute the code in the application, however, I don't think this would be the best option to get the result I need (not even the safest, even if the rules are encrypted).
Structure I am using now is:
app
controller [controllers]
model [models] [aqui são aplicados as regras do banco de dados]
entity [entidades do banco de dados]
repository [model <=> entity]
helper [helpers]
view [views]
theme [themes]
config
[configurações da aplicação]
data
logs [app logs]
cache [view cache]
public
[módulos angular, assets, index.php e .htaccess]
vendor
[libraries, app-core]
The rules would be applied something like this:
// Random key (config)
define('PRIVATE_KEY', 'SECURE_RANDOM_KEY');
// antes
foreach ( regras as regra )
parse(decode(regra, PRIVATE_KEY));
// continua execução
Any ideas on how I could improve this?
Answer:
Why don't you use classes? For example:
interface Regras {
public function execute();
}
class RegrasApp implements Regras {
public function execute() {
// suas regras aqui
}
}
$regras = new RegrasApp();
$regras->execute();