Stupid

A simple expert system processor.

Stupid is designed to work like a simple expert system. At first you declare all the rules and actions. Starting the chain reaction it will evaluate rules and trigger the most appropriate action.

Stupid system will trigger ONLY THE FIRST matching rule and no other one. This cannot be changed.

How to define rules

Stupid system is designed to be modular. Stupid class is a rule evaluator by using registered StupidCondition evaluators. There are some standard evaluators that ship with the engine but you can always expand it.
Every evaluator has a unique "type", which is used when we are defining rules along with specific evaluator parameters. All the parameters of each rule are given in an associative array. Example

 // This rule uses grouping (parenthesis) in regex that act as backreferences
 // and are given as argument in the action 
 Stupid::add_rule('show_news',
     array('type' => 'url_path', 'path' => '/\/news\/([\d]+)/'));
 // A rule that uses more than one condition
 Stupid::add_rule('create_news',
     array('type' => 'url_path', 'path' => '/\/news\/\+create/'),
     array('type' => 'auth', 'op' => 'ingroup', 'group' => 'admin'));
 // Evaluate rules and trigger apropriate action
 
 // Show news implementation
 function show_news($id)
 ...
 
 // Create news implementation
 function create_news()
 ...
You can see add_rule() for syntax information.

Standard Condition Evaluators

Stupid system ships with a set of standard evaluators, those evaluators will probably fullfill the needs of most cases. Each evaluator has its own parameters and you should read its documentation for more information.

sque