Source for file Ruleloaderstrategy.php

Documentation is available at Ruleloaderstrategy.php

  1. <?php  if defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. abstract class RuleLoaderStrategy {
  4.  
  5.     public $rule = NULL;
  6.     
  7.     public $ruleContext = NULL;
  8.  
  9.     function RuleLoaderStrategy({
  10.         $this->rule = new Rule();
  11.         $this->ruleContext = new RuleContext();
  12.     }
  13.     
  14.     abstract public function loadRule$fileName );
  15.     
  16.     abstract public function loadRuleContext$id );
  17.     
  18.     protected function processRuleStatement$tokens$ruleOrRuleContext {
  19.         if$tokens== 'IS' {
  20.             $ruleOrRuleContext->addProposition$tokens](bool)$tokens);
  21.         }
  22.         elseif$tokens== 'EQUALS' {
  23.             $ruleOrRuleContext->addVariable$tokens]$tokens);
  24.         }
  25.     }
  26.     
  27.     protected function processRuleContextStatement$tokens$args {
  28.         $ruleElementName      $tokens];
  29.         $ruleElementValue     null;
  30.         
  31.         $ruleElementValue $this->getRuleElementValue$tokens$args );
  32.         $this->ruleContext->addVariable$ruleElementName$ruleElementValue );
  33.     }    
  34.     
  35.     protected function processOperator$tokens$ruleOrRuleContext {
  36.         $ruleOrRuleContext->addOperator$tokens);
  37.     }
  38.     
  39.     protected function getRuleElementValue$tokens$args {
  40.         $ruleElementType      $tokens];
  41.         $ruleElementName      $tokens];
  42.         $sql                  $tokens];
  43.         $ruleElementValueType trim$tokens);
  44.         $ruleElementValue     null;
  45.         // Query the database
  46.         $CI =get_instance();
  47.         $query $CI->db->query$sql$args );
  48.         $result $query->result_array();
  49.         // Get the value
  50.         $ruleElementValue array_poparray_values$result) );
  51.         // Set the data type
  52.         settype$ruleElementValue$ruleElementValueType );
  53.         return $ruleElementValue;
  54.     }
  55.     
  56.     protected function getStatements$fileName {
  57.         $lines array();
  58.         $ruleFile fopen$fileName'r' );
  59.         if$ruleFile {
  60.             while!feof$ruleFile ) ) {
  61.                 $line trimfgets$ruleFile ) );
  62.                 if!empty$line and !$this->isCommentStatement$line ) ) {
  63.                     $lines[$line;
  64.                 }
  65.             }
  66.         }
  67.         else {
  68.             die'Failed to open stream: ' $fileName ' does not exist.' );
  69.         }
  70.         fclose$ruleFile );
  71.         return $lines;
  72.     }
  73.     
  74.     protected function isCommentStatement$text {
  75.         $text trim$text );
  76.         return strstr$text'#' == $text );
  77.     }    
  78. }
  79. ?>

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