V
V
Vladislav Radzimovsky2014-05-06 15:24:21
PHP
Vladislav Radzimovsky, 2014-05-06 15:24:21

Dynamic creation/deletion of rules for PHP daemon

Hello. The problem lies in the fact that you need to set new rules to the PHP daemon using the graphical interface. Let's say there are such rules:
If id == 1 -> Send e-mail with content ($mail);
If id == 2 -> Delete user;
Etc.
And suppose you need to add the 3rd rule through the interface, so that it would also be executed every time the daemon is started:
If id == 5 -> Delete user;
I'm not interested in the implementation itself, but in how to implement it most correctly. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Valinurov, 2014-05-06
@Lafafm

1) Let's say there is an array $rules - the values ​​of which will be anonymous functions, where, for example, id or other parameters will be passed.
2) Rules are created in the graphical editor and saved as files, something like
<?php
$rules[]= function(..) {..}
3) Files are included in the right place in the code and the $rules array is collected into the rules array
4) Next, iterate over the array and execute the functions

$array = array(
    1 => function() { echo 'test 1'; },
    2 => function() { echo 'test 2'; }
);

foreach ($array as $key => $fun)
    $fun();

Another thing, of course, the approach is not entirely safe.

A
Alexander Kubintsev, 2014-05-07
@akubintsev

For me, the most correct solution seems to be the creation of my own conditional language interpreter, which can describe the rules. Then there shouldn't be any security issues.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question