Source for file Ruleset.php

Documentation is available at Ruleset.php

  1. <?php if defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class RuleSet {
  4.     var $name;
  5.     var $rules;
  6.     var $ruleOverrides;
  7.     
  8.     function RuleSet$name {
  9.         $this->name = $name;
  10.         $this->rules = array();
  11.         $this->ruleOverrides = array();
  12.     }
  13.     
  14.     function __construct$name {
  15.         $this->name = $name;
  16.         $this->rules = array();
  17.         $this->ruleOverrides = array();
  18.     }
  19.     
  20.     function addRule$rule {
  21.         array_push$this->rules$rule );
  22.     }
  23.     
  24.     function addRuleOverride$ruleOverride {
  25.         array_push$this->ruleOverrides$ruleOverride );
  26.     }
  27.     
  28.     function evaluate$ruleContext {
  29.         // Each Rule in the RuleSet is evaluated, and the 
  30.         // results ANDed together taking account of any RuleOverrides
  31.         $resultsForRules array();
  32.         // Accumulate the results of evaluating the Rules
  33.         foreach$this->rules as $r {
  34.             $result $r->evaluate$ruleContext );
  35.             $resultsForRules$r->name $result;
  36.         }
  37.         // Apply the RuleOverrides
  38.         foreach$this->ruleOverrides as $ro {
  39.             $result $resultsForRules$ro->ruleName ];
  40.             if$result {
  41.                 $result->value $ro->value;
  42.             }
  43.         }
  44.         // Work out the final result
  45.         $finalResult true;
  46.         foreacharray_values$resultsForRules as $res {
  47.             $finalResult $finalResult and $res->value );
  48.         }
  49.         return new Proposition$this->name$finalResult );
  50.     }
  51. }
  52.  
  53. /* End of file Ruleset.php */
  54. /* Location: ./system/application/libraries/php-rules/Ruleset.php */

Documentation generated on Thu, 24 Mar 2011 21:27:42 -0500 by phpDocumentor 1.4.1