Source for file Sqlfileloaderstrategy.php

Documentation is available at Sqlfileloaderstrategy.php

  1. <?php  if defined('BASEPATH')) exit('No direct script access allowed');
  2. /** 
  3.  * Strategy pattern for loading a RuleContext from a file in the format
  4.  * <pre>Rule_Element_Type|Rule_Element_Name|SQL_Statement|Expected_Return_Data_Type_from_SQL_Query</pre>
  5.  * @author Greg Swindle <greg@swindle.net>
  6.  * @version 0.2
  7.  * @package Phprules
  8.  */
  9. /**
  10.  * @access public
  11.  * @var Rule 
  12.  */    
  13.     public $rule;
  14. /**
  15.  * @access public
  16.  * @var RuleContext 
  17.  */
  18.     public $ruleContext;
  19. /**
  20.  * Constructor.
  21.  * @access public
  22.  */
  23.     function SqlFileLoaderStrategy({
  24.         parent::RuleContextLoaderStrategy();
  25.     }
  26. /**
  27.  * Load a RuleContext based on the elements listed in {@link $fileName}
  28.  * @access public
  29.  * @param string $fileName The path to a *.sql.con file.
  30.  * @param int $id 
  31.  * @return RuleContext 
  32.  */
  33.     public function loadRuleContext$fileName$id {
  34.         $STATEMENT 4;
  35.         // $statements = $this->getStatements( $fileName );        
  36.         $statements $this->getStatements$fileName );
  37.         foreach$statements as $statement {
  38.             $tokens preg_split'/[\|]+/'$statement );
  39.             // Every statement in the RuleContext file should have 
  40.             // four (4) tokens. If not, ignore it.
  41.             ifcount$tokens == $STATEMENT {
  42.                 $this->processRuleContextStatement$tokens$id );
  43.             }
  44.         }
  45.         return $this->ruleContext;
  46.     }
  47.     
  48.     protected function getRuleElementValue$tokens$args {
  49.         $ruleElementType      $tokens];
  50.         $ruleElementName      $tokens];
  51.         $sql                  $tokens];
  52.         $ruleElementValueType trim$tokens);
  53.         $ruleElementValue     null;
  54.         // Query the database
  55.         require_once BASEPATH.'database/DB'.EXT;
  56.         $db DB(''false);
  57.         $query $db->query$sql$args );
  58.         $result $query->result_array();
  59.         // Get the value
  60.         $ruleElementValue array_poparray_values$result) );
  61.         // Set the data type
  62.         settype$ruleElementValue$ruleElementValueType );
  63.         return $ruleElementValue;
  64.     }
  65.     
  66.     protected function processRuleContextStatement$tokens$args {
  67.         $ruleElementName      $tokens];
  68.         $ruleElementValue     null;
  69.         
  70.         $ruleElementValue $this->getRuleElementValue$tokens$args );
  71.         $this->ruleContext->addVariable$ruleElementName$ruleElementValue );
  72.     }
  73. }
  74. ?>

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